liveBook · Manning

Bit-precise type

As explained in Modern C, Third Edition

A bit-precise type is a C integer type with a precisely specified width in bits.

A three-bit declaration

C23 lets a declaration specify its width directly: unsigned _BitInt(3) u3 = 7wbu; signed _BitInt(3) s3 = 3wb;. The unsigned object represents values from 0 through 7, while the signed object represents values from -4 through 3. section 5.7.7

A bit-precise type is a C integer type whose width is specified in bits rather than selected from the usual standard integer widths. C23 introduces the _BitInt(N) syntax. Integer literals can use wb or WB, optionally combined with u or U; their type uses the least width that can represent the literal's value and signedness. section 5.7.7 section 5.3

Several rules determine how these types behave:

  • Operations compute within the maximal operand width. Adding a three-bit unsigned value to a one-bit unsigned value therefore produces an unsigned _BitInt(3) result; a mathematical result of 8 wraps to 0. section 5.7.7
  • Available widths run from 1 bit for unsigned types and 2 bits for signed types through BITINT_MAXWIDTH, defined in <limits.h>. section 5.7.7
  • The maximum supported width is at least ULLONG_WIDTH, allowing exact-width constants beyond ordinary integer literal facilities when the implementation supports them. section 5.7.7

How Modern C, Third Edition covers it

How deep it goes
Defines syntax, literal typing, width limits, operand-width arithmetic, and wrapping, without descending into implementation representation.
Examples
Uses three-bit declarations, width-limited addition, boundary bit patterns, and a possible 127-bit-precision literal.
What it assumes
Assumes familiarity with C integer literals, signedness, and ordinary integer arithmetic.
What you can do after
Apply it via C23 _BitInt declarations and wb or WB literal suffixes to express exact-width integer values.
How it connects
Connects integer literals with signedness, exact widths, integer arithmetic, and modular wrapping.

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.