C++ disallows reinterpret_cast
from int
to float
as far as I know, and using a union
or pointer cast to reinterpret an int
to a float
or vice versa or even an int
to a short[2]
is undefined behavior. In C using a union is valid but using a pointer cast remains invalid. Most languages have no facilities to reinterpret the bits of one type to another.
Why are languages often averse to reinterpret/bitcasting a type to an 'unrelated' type. What are the advantages or disadvantages of allowing this?