I use a datastructure in my project and in the context of a paricular structure i have a doubt about strucure padding. First Look at the strucure given below. I use Visual S
While all the answers saying that it's up to the compiler are correct, because it is up to the compiler, the language specification places some limitations on the layout. These restrictions apply to all structures in C, "plain old data" in C++03 (which basically means only using features from C) and "standard-layout" structures in C++11 (which allows having constructor and destructor). The restrictions are:
The restriction to standard layout is important. Neither holds for classes that have base classes or virtual members.
Now when combined with the desire not to waste memory, this actually leaves only one practical algorithm, that is therefore used by all compilers. Which does not mean that all compilers will produce the same layout for the same input, because the sizes and alignment requirements for various primitive types differ between platforms. The algorithm is:
(I am almost certain MSDN for MSVC++ describes this somewhere, but couldn't quickly find it)