5.7.12.8 Pack-struct Option
The -fpack-struct
option packs all structure members together without padding bytes between them. Typically, this option is not used, since the structure members might become unaligned and the code required to access them becomes sub-optimal. Additionally, the offsets of members within such structures won’t agree with those for unpacked (aligned) structures in system libraries.
Code must take special care accessing packed structure members via a pointer. Unaligned access is not permitted on some Cortex-M devices and attempting such access will cause a hardfault exception.
The -fno-pack-struct
option chooses a structure arrangement that will produce optimal code, potentially placing padding bytes between members to ensure they are properly aligned for the device. This is the default action if no option is specified.