public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Question about bitfields with aligned attribute.
@ 2022-05-24 14:29 Kaz Kylheku
  0 siblings, 0 replies; only message in thread
From: Kaz Kylheku @ 2022-05-24 14:29 UTC (permalink / raw)
  To: gcc-help

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-24 14:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24 14:29 Question about bitfields with aligned attribute Kaz Kylheku

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).