This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strict aliasing can not be turned off


"Liu, Lei" <lei.liu2@windriver.com> writes:

> Here is my program.
>
> #include <stdio.h>
>
> struct s1 {
>   unsigned int a,b,c;
> };
> struct s2 {
>   unsigned int b,c;
> };
>
> int main(void)
> {
>   struct s1 s;
>   s.c =  0xdead;
>   struct s2 *p = (struct s2*)&s.b;
>   p->c = 0xbeef;
>   printf("s.c=%04x\n", s.c);
>   return 0;
> }
>
> I compile this code with '-O2' flag and get a 's.c=dead'. It's
> reasonable under strict aliasing rule. But when I recompile it with
> -O2 -fno-strict-aliasing', the output is still 's.c=dead'.

I don't see this when I use -fno-strict-aliasing.  I see the "s.c=beef"
as you expect.  That is with gcc 4.4.3 on x86_64.  What version of gcc
are you using?

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]