liveBook · Manning

Evaluation

As explained in Modern C, Third Edition

An evaluation is the execution of a C expression or other construct to determine its value and associated effects.

An evaluation executes a C expression or other construct, producing intermediate values and possibly changing program state. Its effects can include changing the point of execution, computing values, storing values, performing I/O, or changing hidden state such as an atomic flag or mutex state. section 21.0

Even a discarded expression has an effect

The expression `(void)0;` discards its intermediate value, but evaluation still advances the point of execution to the next statement. Therefore, every evaluation has an effect, even when it performs no visible computation or store. section 21.0

Use ordering relations to reason about evaluations across one or more threads:

  • Within one thread, sequenced-before evaluations also participate in the happened-before relation. section 21.1
  • Between threads, synchronization through atomic operations or specified library calls supplies ordering information. section 21.1
  • Modifications of one atomic object follow a modification order consistent with each participating thread’s sequenced-before relation. section 21.1
(void)0;

Inspect the minimal expression that demonstrates why evaluation still changes the abstract execution state when its intermediate value is discarded. section 21.0

How Modern C, Third Edition covers it

How deep it goes
Defines effects and relates evaluations through sequencing, synchronization, and atomic modification order without detailing hardware execution.
Examples
Uses `(void)0`, atomic increments and assignments, and a two-thread modification-order diagram.
What you can do after
Evaluate effects and reason about correctness or performance using sequencing, synchronization, and atomic modification order.
How it connects
Connects evaluations to effects, sequenced-before, happened-before, synchronization, atomic objects, and modification order.

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.