SPRU514Z July 2001 – October 2023 SM320F28335-EP
When the compiler determines the layout of a structure, it provides as many words as are needed to hold all of the members, while complying with each member's alignment constraint. This means that padding bytes may be placed between members and at the end of the structure. Each member is aligned as its type requires.
Types with a size of 16 bits are aligned on 16-bit boundaries. Types with a size of 32 bits or larger are aligned on 32-bit (2 word) boundaries. For details on EABI field alignment, refer to the C28x Embedded Application Binary Interface (EABI) Reference Guide (SPRAC71).
However, bit-fields may not be aligned as strictly as the declared type of the bit-field would be if it were not a bit-field. Bit-fields are packed in the order seen in the source code. The least significant bits of the structure word are filled first. Bit-fields are allocated only as many bits as requested. Bit-fields are packed into adjacent bits of a word.
For COFF, bit-fields do not overlap the following:
If a bit-field would overlap into the next boundary, the entire bit-field is placed at the next boundary. The following table provides examples:
Description | Example | Contents of Structure (in Little-Endian Order) |
---|---|---|
The bit-fields A and B in this example fit within 32-bit boundaries. |
|
|
If A is increased to 9-bits, the most significant bit of B would span a 32-bit boundary. So, B is placed at the next 32-bit boundary. |
|
|
If B is increased to 25-bits, it would span a 32-bit boundary if placed directly after an 8-bit A. So, B is placed at the next 32-bit boundary. |
|
|