Re: strict aliasing can not be turned off

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Liu, Lei" <lei.liu2@xxxxxxxxxxxxx> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux