I\'m curious about conventions for type-punning pointers/arrays in C++. Here\'s the use case I have at the moment:
Compute a simple 32-bit checksum over a
I know this thread has been inactive for a while, but thought I'd post a simple generic casting routine for this kind of thing:
// safely cast between types without breaking strict aliasing rules
template
ReturnType Cast( OriginalType Variable )
{
union
{
OriginalType In;
ReturnType Out;
};
In = Variable;
return Out;
}
// example usage
int i = 0x3f800000;
float f = Cast( i );
Hope it helps someone!