liveBook · Manning

Bit padding

As explained in Modern C, Third Edition

Bit padding is unused storage at the bit level within a representation, including bits that do not fall on byte boundaries.

Bit padding is wasted representation space within a value: unlike byte padding, it need not align with byte boundaries and can occupy individual bits. section 6.3.4

An unsigned value used for a four-member set needs only four meaningful bits; its remaining bits are bit padding. Structure fields such as tm_sec can likewise need fewer bits than an int provides. section 6.3.4

C bit-fields reduce this waste by placing a width after a colon in a member declaration. The compiler may coalesce successive fields into larger storage units, while code still accesses them as ordinary members. section 6.3.4

Reading a packed field

A declaration such as tbi_min : 6 reserves six bits for minutes; an expression such as x.tbi_min < 60 uses that field normally.

How Modern C, Third Edition covers it

How deep it goes
Defines bit padding, explains bit-fields and compiler coalescing, but does not specify a universal physical layout.
Examples
Uses unsigned bird sets, struct tm fields, and a time-like structure with explicitly sized fields.
What you can do after
Apply it via C bit-field declarations that assign storage widths to structure members.
How it connects
Connects bit padding with structure members, byte padding, bit-fields, sizeof, and designated initializers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.