I’m struggling to understand this section on bitfields of the C language specification (6.7.2.1.11):
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.
[…]
I always programmed under the assumption that overflowing bitfields are moved onto the next allocation unit; e.g.
struct {
uint8_t bits0_3 : 4;
uint8_t bits4_7 : 4;
uint8_t overflowing: 1; // <-- this bit will overflow into a second byte
};
However, this paragraph specifies that the implementation may decide to make it “overlap adjacent units”. What does this mean exactly? Could the overflowing
bit overlap with bits0_3
as if in a union?