The Private Parts of MStack

The private data of MStack are stackloc, level and next. stackloc keeps track of how many matrices have been pushed onto the stack. It is used as a debugging tool, and as a loop counter in PrintStack().

The variable, level, is the function nesting level. When CleanStack() is called, it only pops matrices off the stack where level is greater than or equal to Dispatch->level. The rule of thumb for altering level is that a function uses matrix assignment, i.e. VMatrix::operator=(). This allows each function to have its own local stack, but all of the local stacks happen to be in the same linked list. level can be modified by the public member functions Declevel() and Inclevel(), which should be used in pairs in functions. DecReturn() also decrements level.

The pointer, next, stores the address of the next matrix in the stack. Thus, the stack is a singly linked list. The last matrix in the stack stores NULL in the value of next. Also, the list can be traversed only by member functions since next is a private element. The reference stored in Dispatch->next is the address returned by DecReturn() and ReturnMat().

The private part of MStack also has one member function, Pop(). Pop() is only called by CleanStack(), so it is not needed as a public function. Pop() works like most other pop routines. It reassigns Dispatch->next, and deletes the matrix pointed to by the original Dispatch->next. Pop() also decrements stackloc. Pop() stops the program if stackloc becomes zero or if Dispatch->next is NULL.