This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: strict aliasing can not be turned off
- From: Ian Lance Taylor <iant at google dot com>
- To: "Liu\, Lei" <lei dot liu2 at windriver dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 03 Aug 2010 01:40:46 -0700
- Subject: Re: strict aliasing can not be turned off
- References: <4C578986.4000909@windriver.com>
"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