liveBook · Manning

Sequenced-before relation

As explained in Modern C

The sequenced-before relation orders evaluations within a thread according to the C program's execution rules.

The sequenced-before relation orders evaluations within one thread according to C's execution rules. If F is sequenced before E, then F happened before E. section 19.1

Assignment before a switch

If an assignment to command[0] is sequenced before a switch statement, every switch case is executed after the assignment, or at least perceived as happening later. Passing command to nested calls below ungetc therefore provides the modified value. TAKEAWAY: C's grammar establishes this ordering within the thread. section 19.1

This relation supplies one part of the happened-before relation. Ordering between threads instead comes from synchronization, including atomic operations and certain C library calls. section 19.1

How Modern C covers it

How deep it goes
Defines the relation through a happened-before rule and a switch example, but defers cross-thread ordering to synchronization.
Examples
Uses a command[0] assignment before a switch and nested calls below ungetc to show an updated value being observed.
What you can do after
Evaluate within-thread ordering and determine when a later statement observes an earlier assignment.
How it connects
Links C grammar with the happened-before relation, threads, synchronization, atomic operations, and C library calls.

Also explained in

Compare how 2 books explain sequenced-before relation →

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.