liveBook · Manning

Opaque object

As explained in Modern C

An opaque object is an object whose representation and contents can be accessed only through operations explicitly permitted by its abstraction.

An opaque object exposes no directly usable representation or contents; programs handle it only through operations permitted by its abstraction. In C, pointers illustrate this boundary: their binary representation is platform-dependent and treated as irrelevant, while initialization, assignment, evaluation, and later pointer operations remain available. section 6.2

Pointer states

The declarations `char const*const p2string = "some text";`, `char const*const p2nothing = 0;`, and `char const*const p2empty = "";` represent three different cases: a valid pointer, a null pointer, and a pointer to an empty string. A pointer initialized or assigned with `0` is null and evaluates false in a logical expression. An uninitialized pointer, such as `char const*const p2invalid;`, is indeterminate; using it leads to undefined behavior. section 6.2

Opaque structures apply the same separation to library interfaces. A header can forward-declare `struct toto` and expose functions accepting or returning `struct toto*` without revealing the structure definition. Client code can use the interface, while the implementation retains control of the representation. section 11.2

Keep these distinctions visible:

  • A null pointer is not a pointer to an empty string. section 6.2
  • Hiding a pointer inside a typedef can conceal that `0` is a meaningful argument. section 11.2

How Modern C covers it

How deep it goes
Defines permitted pointer operations and states, then explains forward declarations, stopping short of structure implementation details.
Examples
Uses string pointers, empty and null pointers, indeterminate pointers, and a forward-declared `struct toto` interface.
What it assumes
Assumes basic C declarations and initialization while introducing pointer syntax, nullness, and forward-declared structures.
What you can do after
Evaluate C pointer states and design interfaces that conceal structure representations without hiding pointer semantics.
How it connects
Connects pointers with structures, null pointers, typedefs, library interfaces, and undefined behavior.

Also explained in

Compare how 2 books explain opaque object →

Related concepts

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