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

d_layer dome at koganet.ne.jp
Wed Aug 4 18:46:22 CEST 2004


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.

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.

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)

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

-- 
d_layer

navaraf at osexperts.com wrote:
> CVSROOT: /CVS/ReactOS
> Module name: reactos
> Repository: reactos/ntoskrnl/
> Changes by: navaraf at mok.osexperts.com 04/08/03 19:27:07
> 
> Modified files:
> reactos/ntoskrnl/: Makefile 
> 
> Log message:
> - Change -fno-strict-aliasing to -Wno-strict-aliasing for optimized builds.



More information about the Ros-kernel mailing list