Here the question is if the behaviour of some compilers is correct and standard.
My understanding of the reinterpret_cast ( I may be wrong ) is that when A a;B b;
then reinterpret_cast<A>b
is equivalent to *((A*)&b)
.
According to that vision the code bellow should work but in g++
it doesn't is it standard ?
struct A{
int a;
};
int main(int argc, char **argv)
{
struct A x;
x.a=5;
int b=*reinterpret_cast<int*>(&x);
// the previous works but it should work as bellow
int b=reinterpret_cast<int>(x);
return 0;
}