This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Some strict aliasing related fun
- From: "corey taylor" <corey dot taylor at gmail dot com>
- To: "Raymond Sheh" <rsheh at cse dot unsw dot edu dot au>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 27 Nov 2007 22:26:52 -0500
- Subject: Re: Some strict aliasing related fun
- References: <474CCDC9.4000604@cse.unsw.edu.au>
On Nov 27, 2007 9:09 PM, Raymond Sheh <rsheh@cse.unsw.edu.au> wrote:
> whole thing goes random with -O3. Adding -fno-strict-aliasing makes it
> work again but compiling with only -fstrict-aliasing doesn't break it so
> it looks like a combination of things.
You don't see warnings with -fstrict-aliasing?
> float floatblah(float in)
> {
> unsigned long retval =
> byte_manipulation_function_that_happens_to_take_ulongs(*((unsigned
> long*)(&in)));
> return *((float*)(&retval));
> }
You realize of course, this is invalid for 64-bit since float is
32-bit and unsigned long is 64-bit on 64-bit linux.
Why can't you use the union for type-punning here?
union { float a; unsigned long b; };
a = in;
b = im_not_typing_that(b);
return a;
corey