int a = 42;
float b = *((float*)&a); /*
*/
But the cast doesn't do it, the dereference does, by "creating" an
lvalue that designates the object with a different type. As far as the
cast goes, float* is not required to have the same representation as
int* -- although in practice it always does; on machines where data
pointers vary it is character and void pointers that are different.
Of course this is not portable, how can you *portably* interpret
a 'float' from an 'int' bit pattern anyway? Applying a different
type to the same representation is a rather dubious requirement,
IMNSHO. (Yes, I know that it was your point.)
In general yes, although my point was really that even in those cases
where it does make sense C and C++ still don't guarantee it.
Cf Ada, where you have substantial control over some representations,
and extensive inquiries into all of them which can verify that they
are as you expect, so it can be portable to do this, at least to the
extent that it will either work or give a clear error which you might
well be able to recover from; nothing undefined or unpredictable.
- David.Thompson1 at worldnet.att.net