liveBook · Manning

Control flow

As explained in Modern C, Third Edition

Control flow is the order in which execution proceeds among a program's operations and functions.

Control flow is the order in which a program's statements and functions execute. In C, ordinary sequencing can be understood from syntax and controlling expressions, while function calls temporarily suspend the caller until a return transfers execution back. section 2.4.3 section 19.0

Use these structural ideas to read control flow:

  • Treat a basic block as a maximal sequence that begins at one entry point and continues unconditionally to its end. section 19.0
  • Recognize block boundaries at compound-statement beginnings, labels, conditional or loop bodies, return statements, goto targets, and selected function calls. section 19.0
  • Prefer visibly structured compound statements and comprehensive control statements; buried jumps and overly intricate controlling expressions make flow difficult to follow. section 10.2
  • Use functions as modular control-flow units: a call suspends the current execution point, and return resumes it or passes control onward. section 2.4.3

A small program's execution

Execution begins in a platform-provided startup routine, enters main, and then calls printf. While printf executes, main is suspended; printf returns to main, and main's return passes control back to the startup routine, ending the program from the programmer's viewpoint. section 2.4.3

Figure 2.1 Execution of a small program
figure

Trace the transfers among startup code, main, and printf in the execution schematic. section 2.4.3

How Modern C, Third Edition covers it

How deep it goes
Descends from function returns to basic-block boundaries and structured composition, while deferring detailed signal and jump variations.
Examples
Uses startup-to-main-to-printf execution, function returns, compound statements, buried jumps, and intricate controlling expressions.
What it assumes
Assumes basic C knowledge while deriving flow from syntax, controlling expressions, compound statements, and function calls.
What you can do after
Evaluate/understand C execution paths by identifying basic blocks, function suspension and return, and visibly structured branching.
How it connects
Connects control flow with functions, return statements, basic blocks, conditionals, loops, goto, signals, and structured programming.

Also explained in

Compare how 4 books explain control flow →

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.