Chapter 17. Variations in control flow


This chapter covers

  • Understanding normal sequencing of statements in C
  • Making short and long jumps through code
  • Function control flow
  • Handling signals

The control flow (see figure 2.1) of program execution describes how the individual statements of the program code are sequenced: that is, which statement is executed after another. Up to now, we have mostly looked at code that let us deduce this control flow from syntax and a controlling expression. That way, each function can be described using a hierarchical composition of basic blocks. A basic block is a maximum sequence of statements such that once execution starts at the first of these statements, it continues unconditionally until the last, and such that all execution of any statement in the sequence starts with the first.

If we are supposing that all conditionals and loop statements use {} blocks, in a simplified view such a basic block

  • Starts either at the beginning of a {}-block or a case or jump label
  • Ends either at the end of the corresponding {} block or at the next
    • Statement that is the target of a case or jump label
    • Body of a conditional or loop statement
    • return statement
    • goto statement
    • Call to a function with special control flow

17.1. A complicated example

17.2. Sequencing

17.3. Short jumps

17.4. Functions

17.5. Long jumps

17.6. Signal handlers