Cast alignment warnings
Russ Allbery
rra at stanford.edu
Mon Aug 1 19:28:29 UTC 2011
Julien ÉLIE <julien at trigofacile.com> writes:
> On a Debian sparc64 server (TI UltraSparc IIe Hummingbird), I encounter
> cast alignment errors:
> /home/iulius/autobuild/bin/gcc-core-4.6.1/bin/gcc -g -O2 -DDEBUG=1 -Wall -W -Wendif-labels -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Werror -g -O2 -I../include -c network.c
> network.c: In function ‘network_sockaddr_sprint’:
> network.c:611:15: error: cast increases required alignment of target type [-Werror=cast-align]
http://comments.gmane.org/gmane.comp.gcc.help/29997
Basically, it's an unhelpful warning, since there isn't really anything
that you can do to fix it. You have to make sure you don't create a
struct of type sockaddr on the stack, since it may not be aligned
properly, but as long as you create a sockaddr_in, sockaddr_in6, or
sockaddr_storage and are only casting to and from sockaddr, there isn't
any actual problem.
I've stopped using -Wcast-align because it seems to only produce these
false positives in the sort of code I usually work on. People who use the
warning paper around it by casting to void * first, which doesn't actually
fix anything, just hides the issue from the compiler and makes the code
more complicated. That's the mark of a useless warning to me.
--
Russ Allbery (rra at stanford.edu) <http://www.eyrie.org/~eagle/>
Please send questions to the list rather than mailing me directly.
<http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
More information about the inn-workers
mailing list