active activation context

active activation context

Performa 07: Tor Lindstrand & Mårten Spångberg's "International Festival: On the Town" Press Screening at Storefront of Art & Architecture

In computer science, a call stack is a dynamic stack data structure which stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack , control stack , function stack , or run-time stack , and is often shortened to just "the stack".

A call stack is often used for several related purposes, but the main reason for having one is to keep track of the point to which each active subroutine should return control when it finishes executing. (The active subroutines are those which have been called but have not yet completed execution by returning.) If, for example, a subroutine DrawSquare calls a subroutine DrawLine from four different places, the code of DrawLine must have a way of knowing where to return. This is typically done by code for each call within DrawSquare putting the address of the instruction after the particular call statement (the "return address") onto the call stack.

Since the call stack is organized as a stack, the caller pushes the return address onto the stack, and the called subroutine, when it finishes, pops the return address off the call stack (and transfers control to that address). If a called subroutine calls on to yet another subroutine, it will push its return address onto the call stack, and so on, with the information stacking up and unstacking as the program dictates. If the pushing consumes all of the space allocated for the call stack, an error called a stack overflow occurs. Adding a subroutine's entry to the call stack is sometimes called winding ; conversely, removing entries is unwinding .

There is usually exactly one call stack associated with a running program (or more accurately, with each task or thread of a process), although additional stacks may be created for signal handling or cooperative multitasking (as with setcontext). Since there is only one in this important context, it can be referred to as the stack (implicitly, "of the task").

In high-level programming languages, the specifics of the call stack are usually hidden from the programmer. They are given access only to the list of functions, and not the memory on the stack itself. Most assembly languages on the other hand, require programmers to be involved with manipulating the stack. The actual details of the stack in a programming language depend upon the compiler, operating system, and the available instruction set.

latest news