I feel like the stack is so mystified because the professors teaching it don't understand it or anything low level themselves. I say this as I am just beginning to learn C
<tech spaceWhen a function is called, a section of memory is "reserved" on top of what is called the stack. This section of memory is the function's stackframe. The stackframe contains all of the variables allocated by the function. The stack is made up of stack frames.
<tech spaceAfter you understand this, the rest is easy. If you want to remove a variable from a stackframe, it has to be both a variable from the frame on the top of the stack and the variable on top of that stackframe.
<tech spacePushing something to the stack is just adding something to the top, and popping is just removing the top item. You can't push or pop any random item. The top of the stack is just a pointer in a CPU register. Popping simply decrements the top stack pointer and pushing simply increments it and stores a value at said address. The list of elements in them are entirely defined by those registers. There is no such thing as removing a value within these bounds. You can write it to be zero, but you can't just remove it.
<tech spaceI think the plate analogy is almost a misnomer because it's easy to visualize but it's easy to forget this fact. You can't remove something from the middle and have the stack collapse on itself.
<tech spacePost too long. Click here to view the full text.