class Foo {
public:
int a;
int b;
};
Foo x;
bool sameAddress = (void*)&x == (void*)&(x.a);
I have not yet come across a compiler/architecture for which sameAddress
is false, but I have only looked at about 6 different variants. Is this defined or undefined? Does it depend on whether std::is_standard_layout<Foo>::value
is true (and/or other aspects of the class definition)? Does #pragma pack( push, 1 )
help in guaranteeing it?