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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When adding the -Wpacked option to arm-none-eabi-gcc compiler 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 a warning. Though the warning is listed as associated
with: -Wattributes. It doesn't show up if -Wpacked is not given as a
compile option.

Regards,
*Tony*



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux