Compilers on each particular platform have their own default "alignment coefficients" (also known as Zimo numbers). Programmers can change this factor by precompiling the command #pragma pack (n), where n is the "alignment factor" you want to specify, and can only be a power of 2.
The alignment rules are as follows:
1. Data member Alignment rules: Structure (struct) (or union), the first data member is placed at offset 0, and the alignment of each data member at a later time is based on the value specified by the #pragma pack and the length of the data member itself, compared to the smaller one.
2, the overall alignment rule of a struct (or union): After the data member has been aligned, the structure (or union) itself is aligned, and alignment is performed in the smaller of the value and structure (or union) of the maximum data member length specified by the #pragma pack.
3, combined with 1, 2 inference: When the n value of the #pragma pack equals or exceeds the length of all data members, the size of this n value will not produce any effect.
4. The offset of the starting address of each member variable in relation to the starting address of the structure must be a multiple of the number of bytes occupied by the type of the variable.
5. Each member variable at the time of storage in accordance with the order in the structure of the application space, in accordance with the above alignment to adjust the position, empty bytes automatically populated.
6. In order to ensure that the size of the structure is a multiple of the number of bytes in the structure (that is, the number of bytes occupied by the type that occupies the maximum space in the structure), the blank bytes are automatically populated as needed after the space is requested for the last member variable. Reference: http://developer.51cto.com/art/201002/183652.htm
http://www.ibm.com/developerworks/library/pa-dalign/