IT lexicon › Programming › Bit field

Bit field

Programming På svenska → Updated: 2026-11-03

C's way of naming individual bits of an integer inside a struct — pleasant to read, and almost entirely unspecified in how it lands in memory.

Write unsigned ready : 1; and a struct member becomes one bit wide, so reg.ready = 1 reads like an ordinary assignment. That is tempting when describing a hardware register. The catch is that the standard leaves bit order, padding and the underlying storage unit to the compiler, so the same struct can lay out differently across compilers or between architectures of different endianness.

Every write is also a read-modify-write, which can clobber status bits that clear on read. That is why CMSIS and most vendor headers use masks and shifts instead, and why MISRA C restricts bit fields heavily.

← Back to the lexicon