If you're not familiar with the concept of a stack, here's a brief overview:
A
stack is a abstract data-type which imposes rules on how data is stored inside the structure. The stack follows the LIFO, or last-in-first-out, rule. This rules basically means that what ever gets added to the stack first is removed last. An analogy is a stack of places. In order for you to reach the 3
rd plate, for example, you must remove the first two pates.
In computing, a stack is used to store automatic variables (a piece of storage who's destructor is called at the end of the scope in which it was declared) and/or objects. A stack consists of two primary operations: pushing (adding to the stack) and popping (removing from the stack). When an object is pushed onto the stack, that object is placed on top of the object that was pushed previously. When an object is popped from the stack, the object that's on top of the stack is removed; thus revealing the next object on the stack.
To see how a stack works, consider this example:
1 2 3 4 5
|
int main( )
{
int A_;
int B_;
}
|
Let's walk through this. First, "
A_" is declared and then
pushed onto the stack. "
B_" is then also declared and then pushed onto the stack. When "
main( )" ends, "
B_" is
popped from the stack, followed by "
A_". This is the LIFO rule.
If you want to know more about scopes, stack-frames, and general stack information, just ask :)
Wazzak