Given this code:
#include <iostream>
struct A {
};
struct B {
};
struct C {
};
struct E : A {
int field;
};
struct F : A, B {
int field;
};
struct G : A, B, C {
int field;
};
int main() {
std::cout << _MSC_VER << std::endl;
std::cout << sizeof(E) << std::endl;
std::cout << sizeof(F) << std::endl;
std::cout << sizeof(G) << std::endl;
int o;
std::cin >> o;
return 0;
}
I am given the following output:
1900
4
8
8
Why would F
and G
have sizes of 8
even though their bases are empty?
And why would the size of E
not increase as well?
I am building this with Visual Studio Community 2015, version 14.0.25431.01 Update 3. The MSVC++ version is apparently 9.0.
How come? What rationale is there for such a peculiar memory layout?