Question about bitfields with aligned attribute.

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

 



Hi all, 

I'm observing two contradictory effects in the treatment this structure: 

struct s16 {
  uint8_t x;
  __attribute__((aligned (2))) uint32_t a : 7;
  __attribute__((aligned (2))) uint32_t b : 7;
}; 

Firstly, the aligned attribute is documented as only being capable of increasing
alignment. Yet, what is observed is that it's being honored: bitfield a is placed
at offset 2, and b at offset 4. 

So there is an exception to the aligned attribute's "strengthen only" rule
for bitfields? Where is this documented? 

Secondly, in spite of the aligned attribute being honored, the structure is given
two bytes of padding, making it 8 bytes. Why is that? Nothing in the structure
has more than 2 byte alignment, which requires one byte to make a size of six.

What are the exact rules here? Does the bitfield member carry two alignment
properties: one coming from the attribute syntax, and one from the uint32_t
type? Such that the former is allowed to be smaller, even in the absence of
packed? And then the allocation of the bitfield takes into account the former,
but both are considered for the purposes of struct alignment?

Thanks.



[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