liveBook · Manning

Non-value representation

As explained in Modern C, Third Edition

A non-value representation is a bit pattern that does not represent any valid value of its object type.

A non-value representation is a bit pattern that makes no sense as a value of its object type. C's type system normally keeps representations separated, but pointer misuse can expose storage through the wrong type. Accessing an object with a non-value representation for its type causes program failure. section 11.1.4 section 15.1.6

Boolean representation

A bool has only two proper values, false and true, although it may use at least 8 representation bits. Writing other bits directly can produce a non-value representation or cause the program to interpret the Boolean inconsistently. Store only 0 or 1 in a bool, and do not modify object representation bytes directly. section 15.1.6

Keep representations valid by following these rules:

  • Access an object through its correct type; a pointer must designate an object of the pointed-to type. section 11.1.4
  • Do not dereference pointers beyond an array's objects, even when the pointer value itself is valid. section 11.1.4
  • Treat uninitialized storage and directly altered representation bytes as dangerous sources of value misinterpretation. section 15.1.6

How Modern C, Third Edition covers it

How deep it goes
Defines invalid bit patterns, identifies bool as a concrete case, and stops short of detailing implementation-specific encodings.
Examples
Uses bool's extra representation bits and pointers that reference storage beyond an array.
What it assumes
Assumes familiarity with C objects, types, pointers, arrays, and bit representations.
What you can do after
Evaluate whether pointer accesses and representation changes preserve valid values and object types.
How it connects
Connects object representation with pointers, pointer validity, initialization, bool, and value misinterpretation.

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.