IT lexicon › Programming › Static chain

Static chain

Programming På svenska → Updated: 2026-11-06

A hidden pointer passed to a nested function so it can find the local variables of the function that encloses it.

In Algol 60 and Pascal a function can be defined inside another and read its variables. Those live in the outer function's stack frame, but which frame is meant cannot be worked out from the caller — with recursion there may be many. The fix is an extra, invisible argument pointing at the right frame. Each level points to the next, so a variable three levels out is reached by following the chain three hops. Dijkstra's display from 1960 replaced the chain with a table holding one pointer per nesting level: faster to read, costlier to keep current.

The chain has its own slot in the calling convention. The x86-64 System V ABI reserves r10 for it, and LLVM tags the argument with the nest attribute. GCC's nested functions in C additionally need trampolines on the stack once their address is taken — and with them, an executable stack.

← Back to the lexicon