The C++ standard dictates that member variables inside a single access section must be layed out in memory in the same order they were declared in. At the same time, compilers are free to choose the mutual ordering of the access sections themselves. This freedom makes it impossible in theory to link binaries created by different compilers. So what are the remaining reasons for the strict in-section ordering? And does the upcoming C++09 new C++11 standard provide a way to fully determine object layouts ‘by hand’?
The C++ standard dictates that member variables inside a single access section must be
Share
It’s impossible for a number of reasons, and structure layout is the most minor. vtables, implementations of
operator newanddelete, data type sizes…C compatibility, I would have thought, so that a struct defined in C packs the same way it does in C++ for a given compiler set.
No, no more than the current standard does.
For a
classorstructwith no vtable and entirely private (or public) fields, though, it’s already possible if you use the[u]int[8|16|32|64]_ttypes. What use case do you have for more than this?