I am following Memory Layout And The Stack to understand stack frames..
The Author explains stack frames nicely and says what will be in STACK at given point of time
He also asks some questions below
- Suppose a program makes 5 function calls. How many frames should be on the stack?
- We saw that the stack grows linearly downward, and that when a function returns, the last frame on the stack is deallocated and returned to unused memory. Is it possible for a frame somewhere in the middle of the stack to be returned to unused memory? If it did, what would that mean about the running program?
- Can a goto() statement cause frames in the middle of the stack to be deallocated? The answer is no, but why?
- Can longjmp() cause frames in the middle of the stack to be deallocated?
Below is my attempt to answer above questions
- Suppose a program makes 5 function calls. How many frames should be on the stack?
If the functions are independent of each other,then only main function or main and calling function will be in stack
We saw that the stack grows linearly downward, and that when a function returns, the last frame on the stack is deallocated and returned to unused memory. Is it possible for a frame somewhere in the middle of the stack to be returned to unused memory? If it did, what would that mean about the running program?
I think this is not possible,since this may corrupt memory
I am not sure of rest of the questions.Can you please help on this
let me know if you need more info