The relevant quote I can find is 6.7.2.1 (1), from C99:
An implementation can allocate any addressable storage unit that is large enough to store a bit field. If enough space remains, the bit field that immediately follows the other bit field in the structure should be packed into adjacent bits of the same block. If there is not enough space, then whether a bit field that does not fit will fit in the next block or overlap adjacent units is determined by the implementation. The order of distribution of bit fields within a unit (from high order to low or low order) is determined by the implementation. The alignment of the storage address block is not indicated.
I think unsigned
is not really a type of base unit, but rather is only part of the bitfield declaration itself: T : n
means "take n bits of type T
". The real question is whether an implementation is required to select a "large" unit. For example, it can use three bytes, making a char
block; one for v1
, one for v2
, and the last for v3, v4
. Or it can make the device a 16-bit integer, in which case you only need to use one unit.
However, as you noted, the ordering of bit fields within the device is not defined. The atomic unit of data in C is an address, and bit fields have no addresses. He guaranteed that the address of members of the structure increases in the order of their declaration, but you cannot draw such a conclusion about bit fields (only about their basic units).
source share