I'm not sure if this has been asked before, but I must suppose. Consider a simple line to start the question:
int a ; char b = reinterpret_cast<char> (a);
I understand that reinterpret_cast interprets the bit pattern of type x as type y, ofcouse it should not work due to size mismatch, and in fact it is not.
Now consider the following code:
int a ; char b = static_cast<char> (a);
It works !, Now my question is, how can it work? I mean, does the compiler beat the bits ?, I'm sure sizeof(char) < sizeof(int) . If so, should reinterpret_cast work the same way?
source share