On Tue, 2023-11-28 at 10:13 -0600, Daniel Xu wrote: [...] > > One thing for sure is memory layout of bitfields should be the same > > for both clang and gcc as it is determined by C standard. Register > > representation and how to manipulate could be different for different > > compilers. > > I was reading this thread: > https://github.com/Lora-net/LoRaMac-node/issues/697. It's obviously not > authoritative, but they sure sound confident! > > I think I've also heard it before a long time ago when I was working on > adding bitfield support to bpftrace. > > > [...] Here is a citation from ISO/IEC 9899:201x (C11 standard) §6.7.2.1 (Structure and union specifiers), paragraph 11 (page 114 in my pdf): > An implementation may allocate any addressable storage unit large > enough to hold a bit- field. If enough space remains, a bit-field > that immediately follows another bit-field in a structure shall be > packed into adjacent bits of the same unit. If insufficient space > remains, whether a bit-field that does not fit is put into the next > unit or overlaps adjacent units is implementation-defined. The order > of allocation of bit-fields within a unit (high-order to low-order > or low-order to high-order) is implementation-defined. The alignment > of the addressable storage unit is unspecified.