[haiku-development] Re: Disabling Strict Aliasing for GCC4 Builds

  • From: "Michael Lotz" <mmlr@xxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 18 Apr 2008 00:04:49 +0200

Hi Alex

> I tried compiling that as follows:
> gcc -std=c99 -c -O2 -fstrict-aliasing 3.c
> 
> ... and I got no compiler errors, though I see the problem... I did
> this using gcc " version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)" on my linux
> box...
> 
> Am I providing wrong compiler options (I know that -fstrict-aliasing
> is redundant, but...)? Or is the problem not showing up in this
> particular example?

You'll need -Wall to see the warning. I only tried with what I have 
here:
i586-pc-haiku-gcc (GCC) 4.1.2

int
main(int argc, char *argv[])
{
        double someDouble = 0.0;
        someDouble += 5.0;
        int variable = *(int *)&someDouble;
        someDouble -= 3.0;
        return 0;
}

Compiled with:
/cross-compiler-path/i586-pc-haiku-gcc -c "testalias.cpp" -O2 -o 
"testalias" -Wall;

Got:
testalias.cpp:6: warning: dereferencing type-punned pointer will break 
strict-aliasing rules

Regards
Michael

Other related posts: