SPRUIG8J January 2018 – March 2024
A struct is aligned to a boundary required by the member it contains with the strictest alignment requirement. For example, if the largest alignment required by a member of the struct is 16-bit alignment (for example, a short), then the entire struct is aligned to a 16-bit boundary. If the struct contains a type that requires 64-bit alignment (such as a double or long), then the struct is aligned to a 64-bit boundary.
If a struct member is itself a struct, the size and alignment of the inner struct must be determined before the size and alignment of the outer struct may be determined.
Members of structs have sizes and alignments equal to those they would have as independent objects, unless the packed attribute is used. An array member of a struct is aligned to the alignment of its element type; this may differ from the alignment the element would have if it were an independent top-level (static) object.
Structs always have size equal to a multiple of the struct alignment. This sometimes requires padding after the last member to round the size up to a multiple of the struct alignment. The size of a structure includes any necessary padding between members. For example, if the largest member of a struct is of type float, the size of the struct will be a multiple of 32 bits.
Static scope arrays (sometimes called top-level arrays) are aligned on an 8-byte (64-bit) boundary.