Tech

Function Call Stack & Activation Records–Functions–STRUCTURED PROGRAMMING Course Notes

Function Call Stack & Activation Records

  • Stacks are known as ‘last-in, first-out‘ (LIFO) data structures–the last item pushed (inserted) on the stack is the first item popped (removed) from the stack.
  • The function call stack supports the function call/return mechanism, & the creation, maintenance and destruction of each called function’s automatic variables.
  • Each time a function calls another function, a stack frame, or an activation record, is pushed onto the stack containing the return address that the called function needs to return to the calling function, and the function call’s automatic variables & parameters.
  • The stack frame exists as long as the called function is active. When the called function returns, its stack frame is popped from the stack, and its local automatic variables no longer exist.
  • A stack is a data-structure (i.e., a collection of related data items).
  • One of the most important mechanisms for computer science students to understand is the ‘function call stack‘ (sometimes referred to as the ‘program execution stack‘). This data structure–working “behind the scenes”–supports the function call/return mechanism. It also supports the creation, maintenance and destruction of each called function’s automatic variables. Each time a function calls another function, an entry is pushed onto the stack. This entry, called a ‘stack frame‘ or an ‘activation record‘, contains the return address that the called function needs in order to return to the calling function.