Type-punning
Chris Lattner
clattner@apple.com
Fri Jun 22 18:37:00 GMT 2007
On Jun 22, 2007, at 1:41 AM, Sergei Organov wrote:
> Herman Geza <hg211@hszk.bme.hu> writes:
>
> [...]
>
>> What is the correct way to do this:
>>
>> void setNaN(float &v) {
>> reinterpret_cast<int&>(v) = 0x7f800001;
>> }
>>
>> without a type-prunning warning? I cannot use the union trick here
>
> Why? Won't the following work?
>
> void setNaN(float &v) {
> union { float f; int i; } t;
> t.i = 0x7f800001;
> v = t.f;
> }
__builtin_nan isn't sufficient?
-Chris
More information about the Gcc
mailing list