Call Graph vs Control Flow Graph
People think a call graph and a control flow graph are two names for the same map of a program, and they are not. A call graph is drawn between functions: each arrow means this one calls that one. A control flow graph is drawn inside one function: each arrow is a step, and it splits at each if and loop. Use the first to see how far a change spreads, and the second to find untested paths.
Call Graph
A map of which functions call which, drawn as dots and arrows.
A call graph shows which functions call which other functions. Each function is a dot, and an arrow means this one calls that one. Following the arrows forward shows what a function needs. Following them back shows who needs it. Editors show a small piece of it as the call hierarchy.
Control Flow Graph (CFG)
A map of each path a function can take. It splits at each if and loop.
A control flow graph shows every path a program can take through one function. Each box is a run of steps with no choice in it. An arrow leads to the next box. An if or a loop makes the arrows split or circle back. Tools read it to find code no path can reach, or a path that skips a check.
In one line
- Call Graph
- A map of which functions call which, drawn as dots and arrows.
- Control Flow Graph (CFG)
- A map of each path a function can take. It splits at each if and loop.