Next: Recursion Up: How automatic variables Previous: The stack

Creating and deleting automatic variables

When you enter a new block, storage for the new variables is created at the top of the stack. The complete set of newly used storage is called the current stack frame. The value of the old stack pointer is also pushed onto the stack. The stack pointer is updated to point to the top of the stack frame.

These storage items are linked to the names you use in your program and any values you store will therefore be held in the appropriate part of the current stack frame.

When execution leaves the block, the stack pointer is set back to its old value (read from the stack) and the old stack frame, and linkages, come into play again.

In this way, function calls can be to any depth, providing only that there is enough room within the stack. A function call pushes automatics onto the stack; a return pops them off again.



Next: Recursion Up: How automatic variables Previous: The stack


maspjw@
Tue Sep 27 15:29:34 BST 1994