
On Feb 7, 2008 1:31 PM, Frank Mori Hess <frank.hess@nist.gov> wrote:
On Thursday 07 February 2008 07:40 am, Fernando Cacciola wrote:
Then I suspect you don't really want to "convert" the float to int but to get at the value-representation of the float. If that's the case, you can do this:
char* float_value_rep = static_cast<char*>(static_cast<void*>(&your_float));
Isn't this what reinterpret_cast is for? It wouldn't require bouncing through a void*. Also, to the original poster, don't succumb to the temptation to cast to anything other than a char* (like an int*) or you'll end up in strict aliasing violation hell.
For most uses of reinterpret_cast, it invokes implementation specific behavior. static_cast is portable though. So the latter is preferrable.
-- Frank
Regards, -- Felipe Magno de Almeida