This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

arm-none-eabi-gcc: packed attribute causes inefficient alignment

When adding the -Wpacked option to arm-none-eabi-gcc combiler it issues the following warning:

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;
      |              ^~~

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.