Commit Graph

1 Commits

Author SHA1 Message Date
Nadav Har'El
1f8e0dbbab unaligned: new header file for unaligned access
This patch adds a new header file, "core/unaligned.hh", which defines a
new operation, unaligned_cast<T*>(p). This works exctly like
reinterpret_cast<T*>(p) except it is safe to use even when the address
of p is not a multiple of alignof(T).

A long comment in the header file explains why this unaligned_cast<>
is necessary on some esoteric architectures and to quiet gcc's
-fsanitize=alignment.

The header file also defines a new template for holding an unaligned
version of type - unaligned<T>. unaligned<T> is almost identical to our
existing net::packed<>, so the next patch will implement net::packed
in terms of unaligned<>.

The unaligned_cast<> and unaligned<> templates are of course generally
useful outside the network code, which is why I wanted them out of the
networking header files and namespace.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-15 15:44:56 +02:00