The C++ standard imposes an ordering on class member variables in memory. It says that the addresses of member variables have to increase in the order of declaration, but only inside one access section. Very specifically, this does not seem to prevent compilers from laying out access sections in an interleaved way. For example:
class X {
public:
int i;
int j;
private:
int k;
int n;
}
Does the standard allow compilers to lay out the data members in the order i, k, j, n? This would give compilers some (limited) freedom in optimizing object layout without violating the standard.