Home Page


The Function Call Stack

Program Execution Stack.

When a function is called, it can call other functions and in turn, they can call other functions. The most important thing is that every function will (ideally) eventually terminate back to the caller. In order to do so, we must keep track of the return address. We do so by pushing it onto the call stack.

Every time we call a function, thre is a data structure called a stack frame that gets pushed onto the stack. This stack frame contains a return address for the function being called to give control back to the caller. It anot only contains the return address, but also:

Consists of the local variables that are used within the function (automatic)

When the function is complete, the computer will pop this stack frame off the top of the stack and use the return address to resume execution.

When we make too many function calls without given control back to the caller, we will flood the stack and will cause a stack overflow.