On Mon, 18 Sep 2023, Luck, Tony wrote: > > Since you replied, would you happen to have a pointer something that tells > > (in writing) how the bitfields in C are allocated in case of x86_64? I > > spent a bit of time trying to find something but came up nothing. > > Search engines don't seem to be as good as they used to be (or I'm not as > good at finding the right query). > > There's a bit on page 14 of: > > https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf > > that says bit fields are allocated right to left (which is a good > start). But I thought there was a doc somewhere that gave > more detail about alignment of bitfields. Thanks, appreciated. In this case it is not just about the bitfield itself nor the bit allocation order but sharing the storage unit with another member, and to further complicate things, members have different alignment requirement too (32-bit aligned u8 followed by u32 bitfield). The document states: "Bit-fields obey the same size and alignment rules as other structure and union members." which seems to contradict my test that found that the u32 bitfield won't be 32-bit aligned but gets combined with the 32-bit aligned u8. Perhaps it's because the total number of bits still fits to 32 bits so the bitfield doesn't cross the 32-bit boundary even when combined with the preceeding u8. -- i.