Re: strict aliasing can not be turned off

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

 



Ian Lance Taylor wrote:
"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

I'm using gcc 4.3.3.

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)

Is it a fixed bug of gcc?

Lei


[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