liveBook · Manning

Control flow

As explained in Modern C

Control flow is the order in which execution proceeds among statements and functions in a program.

Control flow is the order in which a program executes statements and functions. A function call temporarily suspends the caller, transfers execution to the called function, and resumes the caller when a return is encountered. section 2.4.3 section 17.0

A call-and-return path

A small program follows this path: platform startup calls main; main calls printf; printf returns to main; main returns EXIT_SUCCESS to the startup routine. The transfers between these functions form the program’s visible control flow. section 2.4.3

Readable C makes the path through execution apparent:

  • Structure statements in visually distinct {} blocks linked by comprehensive control statements. section 10.2
  • Keep control flow obvious rather than burying break, continue, return, or goto inside complicated nested conditionals and loops. section 10.2
  • Treat unusual, densely composed controlling expressions as another source of obscurity and subtle bugs. section 10.2

A basic block is a maximal sequence of statements that executes unconditionally from its first statement to its last. Blocks are joined by if/else and loop structures; return, goto, jump labels, certain case boundaries, and special-control-flow functions end them. section 17.0

Figure 2.1. Execution of a small program

Trace the transfer of execution among startup code, main, and printf in a small C program. section 2.4.3

How Modern C covers it

How deep it goes
Descends from sequencing and returns to basic-block boundaries, while deferring detailed jump and signal behavior.
Examples
Uses a startup-to-main-to-printf execution path, {} blocks, nested jumps, and controlling expressions as examples.
What it assumes
Assumes basic C syntax and controlling expressions, while defining control flow and basic blocks explicitly.
What you can do after
Evaluate/understand execution paths and structure C code so its control flow remains obvious.
How it connects
Links statements, functions, return, if/else, loops, goto, basic blocks, and signals.

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. The section links point to the parts of the book it draws on.