liveBook · Manning

Sequence point

As explained in Modern C

A sequence point is a point in C program evaluation at which specified preceding evaluations are complete before subsequent evaluation proceeds.

A sequence point is a point in C evaluation where specified preceding evaluations are complete before subsequent evaluation proceeds. It serializes execution without necessarily choosing an order between two expressions. section 17.2

 3   unsigned add(unsigned* x, unsigned const* y) {
 4     return *x += *y;
 5   }
 6   int main(void) {
 7     unsigned a = 3;
 8     unsigned b = 5;
 9     printf("a = %u, b = %u\n", add(&a, &b), add(&b, &a));
10   }


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":1},{\"line\":0,\"ch\":2}],[{\"line\":4,\"ch\":20},{\"line\":4,\"ch\":21}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":13}],[{\"line\":4,\"ch\":7},{\"line\":4,\"ch\":15}],[{\"line\":5,\"ch\":7},{\"line\":5,\"ch\":15}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":13}],[{\"line\":4,\"ch\":7},{\"line\":4,\"ch\":15}],[{\"line\":5,\"ch\":7},{\"line\":5,\"ch\":15}],[{\"line\":0,\"ch\":31},{\"line\":0,\"ch\":45}],[{\"line\":1,\"ch\":1},{\"line\":1,\"ch\":2}],[{\"line\":1,\"ch\":7},{\"line\":1,\"ch\":13}],[{\"line\":2,\"ch\":1},{\"line\":2,\"ch\":2}],[{\"line\":5,\"ch\":20},{\"line\":5,\"ch\":21}],[{\"line\":3,\"ch\":1},{\"line\":3,\"ch\":2}],[{\"line\":3,\"ch\":5},{\"line\":3,\"ch\":8}],[{\"line\":6,\"ch\":9},{\"line\":6,\"ch\":12}],[{\"line\":3,\"ch\":9},{\"line\":3,\"ch\":13}],[{\"line\":3,\"ch\":14},{\"line\":3,\"ch\":18}],[{\"line\":4,\"ch\":1},{\"line\":4,\"ch\":2}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":13}],[{\"line\":4,\"ch\":7},{\"line\":4,\"ch\":15}],[{\"line\":5,\"ch\":7},{\"line\":5,\"ch\":15}],[{\"line\":5,\"ch\":1},{\"line\":5,\"ch\":2}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":13}],[{\"line\":4,\"ch\":7},{\"line\":4,\"ch\":15}],[{\"line\":5,\"ch\":7},{\"line\":5,\"ch\":15}],[{\"line\":6,\"ch\":1},{\"line\":6,\"ch\":2}],[{\"line\":6,\"ch\":7},{\"line\":6,\"ch\":13}],[{\"line\":7,\"ch\":0},{\"line\":7,\"ch\":2}]]"}
!@%STYLE%@!

Consider two calls that modify shared variables inside one printf expression. The function calls impose sequence points, but their relative order remains unspecified. section 17.2

One expression, two valid outcomes

Starting with a = 3 and b = 5, evaluating add(&a, &b) first produces a = 8 and b = 13, yielding “a = 8, b = 13”. Evaluating add(&b, &a) first instead yields “a = 11, b = 8”. Both outcomes are well defined because sequencing requires an order, not a particular order. section 17.2

How Modern C covers it

How deep it goes
Defines serialization, distinguishes it from evaluation order, and works through function-call outcomes without developing later sequencing rules.
Examples
Uses two modifying add calls inside printf to demonstrate the outputs produced by alternative evaluation orders.
What you can do after
Evaluate C expressions by separating guaranteed sequencing from an order the language leaves unspecified.
How it connects
Connects expression evaluation with function calls, statements, and sequencing constraints.

Also explained in

Compare how 2 books explain sequence point →

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.