Unit content
Function call stacks and stack frames
When a function calls another function, the caller must preserve enough information to continue after the callee returns. Many runtime systems organize this nested call state using a call stack.
Stack frames
Each active function call has a stack frame containing information such as arguments, local state, saved machine state and a return location.
Conceptually:
main
└─ parse
└─ read_value
The most recently called function returns first, matching the last-in, first-out behaviour of a stack.
Returning
When a function returns, its frame is removed and execution continues at the saved return point in the caller.
Local state belongs to a call
Calling the same function twice can create two distinct active frames. Each invocation can therefore have its own parameters and local variables even though both execute the same function body.
Stack limits
Call-stack storage is finite in real systems. Extremely deep chains of nested calls can exhaust it and cause a stack overflow.
The call stack explains how ordinary nested function calls work and provides the execution model needed to understand recursion.