Re: Some strict aliasing related fun

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Nov 27, 2007 9:09 PM, Raymond Sheh <rsheh@xxxxxxxxxxxxxxx> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux