This is the mail archive of the gcc-help@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: Some strict aliasing related fun


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


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