4 ms·
As mentioned by others, C does not allow reordering of members in structs. However, C++ does! §9.2.12 says: Nonstatic data members of a (non-union) class
by jmgao 13y ago
As mentioned by others, C does not allow reordering of members in structs. However, C++ does!
§9.2.12 says:
Nonstatic data members of a (non-union) class declared without an
intervening access-specifier are allocated so that later members
have higher addresses within a class object. The order of allocation
of nonstatic data members separated by an access-specifier is unspecified (11.1)
This means, that under a strict reading, even the following struct can have its members reordered:
struct foo {
int a;
public:
int b;
}
- ben0x539 13y agoDid this change in C++11 or does this wording mean the same thing? It's not clear to me that the implicitly public a is of a different access control than the explicitly public b according to the following wording: > Nonstatic data members of a (non-union) class with the same access control (Clause 11) are allocated so that later members have higher addresses within a class object. The order of allocation of non-static data members with different access control is unspecified (11).
- aidenn0 13y agoThat's what I was thinking of. Thanks.