In computer science, the control flow or program sequence describes the chronological sequence of the individual commands of a computer program . The control flow of a program is usually specified by the order of the commands within the program, but control structures allow deviations from the sequential processing of the program. The processing sequence of the individual commands, which the program specifies, is determined by control flow dependencies: A single command is either executed when the immediately preceding command has been processed and the program counter has been incremented or when a jump command points to the corresponding location in the memory and passes through the program counter a new value is assigned to the jump command. Both control flow dependencies must be taken into account when executing commands in the program in parallel.
The planned sequence of a program is represented by a so-called program flow chart or the control flow graph. It shows all possible branches within the control flow. The actual control flow is now the command sequence during execution of the program.
The following excerpt from a program implemented in C is considered :
int i = 0; ... /* hier kann i irgendwo geändert werden */ if (i == 5) puts("i==5"); else puts("i!=5");
The control flow graph now looks like this:
|i = 0|
|Yes||i == 5?||No|
|i == 5 \ n||i! = 5 \ n|
The actual control flow of the program now depends on the concrete value of the variable i at the time the if statement is reached.
If the if statement is inside a loop , the alternative branch of the control flow graph could be run through when the loop is repeated.
The analysis of the control flow is part of the program analysis . The application of the program to a test case leads to a certain control flow and can be compared with the expected control flow. This enables potential errors due to incorrect control structures to be detected. A partial evaluation of the test case can also be carried out. In the optimal case (if there are loops ) all commands contained in the control flow graph are also contained in the control flow generated by the test case.