When adding the -Wpacked option to arm-none-eabi-gcc combiler it issues the following warning:
-Wpacked
warning: packed attribute causes inefficient alignment for 'struct field name'
For example,
struct Struct_test { uint32_t ch1; uint16_t ch2; uint32_t ch3; } __attribute__( ( packed ) );
warns about the fields ch1 and ch2:
test.c:12:14: warning: packed attribute causes inefficient alignment for 'ch1' [-Wattributes] 12 | uint32_t ch1; | ^~~ test.c:13:14: warning: packed attribute causes inefficient alignment for 'ch2' [-Wattributes] 13 | uint16_t ch2; | ^~~
test.c:12:14: warning: packed attribute causes inefficient alignment for 'ch1' [-Wattributes] 12 | uint32_t ch1; | ^~~ test.c:13:14: warning: packed attribute causes inefficient alignment for 'ch2' [-Wattributes] 13 | uint16_t
ch2; | ^
~~
As per the manual -Wpacked means: Warn when the packed attribute has no effect on struct layout. But in this case the packed attribute does have an impact on the struct layout as it removes the padding between ch2 and ch3, but still it causes warning. Though the warning is listed as associated with: -Wattributes. It doesn't show up if -Wpacked is not given as compile option.
-Wattributes