Cast alignment warnings

Julien ÉLIE julien at trigofacile.com
Mon Aug 1 20:22:58 UTC 2011


Hi Russ,

>> 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.

After having googled a bit, consecutively to Alexander's and your 
answer, I found out:
     http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=340384

Shouldn't sockaddr_storage be used instead of sockaddr as described in 
this bug on sparc64?



> 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.

Isn't alignment a real bug here?

-- 
Julien ÉLIE

« Un ami fidèle qui parle très bien votre langue et toutes les
   langues vivantes : le latin, le grec, le celte, etc. » (Astérix)



More information about the inn-workers mailing list