Format of Aligned Structures

The data format described here for aligned structures is based on the alignment produced by compiling with the /Sp compiler option.

The C++ compiler may generate extra fields for classes that contain base classes or virtual functions. Objects of these types may not conform to the mapping shown below.

Type struct
Size Sum of the sizes for each type in the struct plus padding for alignment
Alignment IBM C and C++ Compilers determines which element has the most restrictive alignment rule, then aligns the first element according to that rule. The alignment of the individual members is not changed.

In the following example, types char, short, and float are used in the struct. Because float must be aligned on the 4-byte boundary, and because this is the most restrictive alignment rule, the first element must be aligned on the 4-byte boundary even though it is only a char.

struct y {
char char1;   /* aligns on 4 bytes*/
short short1; /* aligns on 2 bytes */
char char2;   /* aligns on byte */
float float1; /* aligns on 4 bytes */
char char3    /*aligns on byte */
};
Storage
Mapping
High memory is to the right.
byte 0 byte 1 byte 2 byte 3 byte 4 byte 5
char1 pad short1 short1 char2 pad
byte 6 byte 7 byte 8 byte 9 byte 10
pad pad float1 float1 float1
byte 11 byte 12 byte 13 byte 14 byte 15
float1 char3 pad pad pad



Data Mapping