SPRAB89A September 2011 – March 2014
Structure members are assigned offsets starting at 0. Each member is assigned the lowest available offset that satisfies its alignment. Padding may be required between members to satisfy this alignment constraint.
Union members are all assigned an offset of 0.
The underlying representation of a C++ class is a structure. Elsewhere in this document the term structure applies to classes as well.
The alignment requirement of a structure or union is equal to the most strict alignment requirement among its members, including bit field containers as described in the next section. The size of a structure or union in memory is rounded up to a multiple of its alignment by inserting padding after the last member. Structures and unions passed by value on the stack have special alignment rules as specified in Section 3.4.
Structures having size 64 bits or less may reside in registers or register pairs while being passed to or returned from functions.
In little-endian mode a structure in a register is always right justified; that is, the first byte occupies the LSB of the register (the even register if a pair) and subsequent bytes of the structure are filled into the increasingly significant bytes of the register(s).
In big-endian mode the following rules govern the layout of structures in registers:
Figure 2-2 depicts the big-endian register representation of structures with sizes of one through eight bytes.
The rationale for this layout is to allow the structure to be copied between registers and memory using the smallest appropriate memory reference; for example, a 2-byte struct uses a 16-bit reference, a 3-byte struct uses a 32-bit reference, a 5-byte struct uses a 64-bit reference, and so on. The structure is left-justified within the size of the containing memory reference.