[ros-kernel] Re: [ros-cvs] CVS Update: reactos

Filip Navara xnavara at volny.cz
Wed Aug 4 18:25:38 CEST 2004


d_layer wrote:

>If you really want to use -fstrict-aliasing, you must fix the
>source code to comply with the strict-aliasing rules.
>Specifying -Wno-strict-aliasing does not help.
>  
>
I always thought that it will not use the strict aliasing
optimalizations on files that don't comply with the rules. These applies
only to few files.

>Because warnings enabled by -Wstrict-aliasing mean "your code is
>breaking the strict-aliasing rules, so gcc may misoptimize your code,"
>ignoring these warnings while specifying -O2 (-fstrict-aliasing)
>might cause you to suffer from mysterious bugs.
>  
>
Hmm, that is bit problematic. The only way we can fix this is breaking
some prototypes. IIRC it applies only to some "undocumented" prototypes
that are described in various book, but I'm not sure. These prototypes
use PVOID* parameters where PVOID is really meant as a pointer to
arbitrary memory. Maybe it would make sense to change these parameters
to ULONG_PTR*, but I'm not sure.

>The strict-aliasing rules are explained in section "6.5  Expressions",
>paragraph #7 of the C99 draft standard:
>http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/n869.txt.gz
>(older ANSI/ISO C standards have essentially the same rules)
>  
>
Thanks, I'll read it.

>The following source code demonstrates the effect of optimizations
>based on the strict-aliasing rules. It prints "0" or "65536" when
>compiled with "gcc -O2" or "gcc -O2 -fno-strict-aliasing", respectively.
>confirmed with gcc 3.3.3/i386.
>----- cut here -----
>#include <stdio.h>
>int main(void) { int packed = 0; *((short *)&packed+1) = 1; printf("%d\n", packed); return 0; }
>----- cut here -----
>
Regards,
Filip



More information about the Ros-kernel mailing list