Wrong RTL instruction deleted
Giovanni Bajo
rasky@develer.com
Mon Dec 27 17:40:00 GMT 2004
Robert Dewar <dewar@adacore.com> wrote:
> The corresponding Ada program:
>
> function Foo return Float is
> function To_Float is new Unchecked_Conversion (Unsigned_32, Float);
> MASK : unsigned := 16#8000_0000#;
> begin
> return To_Float (MASK);
> end Foo;
>
> is certainly 100% valid since the value converted is a valid
> value of the target type.
This is getting off-topic quick, but there is no easy way to do this in C++.
With GNU C/C++, you can use unions:
union IntFloat {
unsigned int i; float f;
};
float To_Float(unsigned int mask)
{
IntFloat if;
if.i = mask;
return if.f;
}
but this is actually undefined behaviour per the ISO C++ Standard. Sometimes
ago, I proposed this new syntax as an extension on comp.std.c++:
float To_Float(unsigned int mask)
{
return reinterpret_cast<float>(mask);
}
but people didn't like it (Gaby Dos Reis among all, IIRC). The funny thing
is, I really really really really need to be able to do something like this,
and there is still no way to do this portably in C++.
--
Giovanni Bajo
More information about the Gcc
mailing list