This is the mail archive of the gcc@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


On Tue, 2007-11-06 at 07:58 -0800, Ian Lance Taylor wrote:
> Joe Buck <Joe.Buck@synopsys.COM> writes:

> In particular people really do write code like
>     int addr = 0x12345678;
>     char* p = (char*)&addr;
>     *p = 1;
> and
>     int f[2] = { 0x80000000, 0 };
>     double d = *(double*)f;
> This is not valid C/C++ code.  

What you mean is that it is not strictly conforming C code.
[You cannot say that for C++, there is no notion of strictly
conforming C++ code]

> But since there is quite a lot of it
> out there, the -fno-strict-aliasing rule makes it work correctly.

Yes. This is overkill for me: making that work would disable
too many optimisations for my taste.

BTW: gcc handles these rules very cleverly indeed. I have
played with some code and things like union-ing an unsigned
char array correctly defeat the optimisations. I'm quite
surprised, this is very hard to get right.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


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