In a previous question (Get object call hierarchy), I got this interesting answer:
The call stack is not there to tell you where you came from. It is to tell you where you are going next.
As far as I know, when arriving at a function call, a program generally does the following:
In calling code:
- store return address (on the call stack)
- save registers' states (on the call stack)
- write parameters that will be passed to function (on the call stack or in registers)
- jump to target function
In called target code:
- Retrieve stored variables (if needed)
- Retrieve stored variables (if needed)
Return process: Undo what we did when we called the function, i.e. unroll/pop the call stack:
- remove local variables from the call stack
- remove function variables from the call stack
- restore registers state (the one we stored before)
- jump to return address (the one we stored before)
Question:
How can this be viewed as something that "tells you where you are going next" rather than "tell you where you came from"?
Is there something in C#'s JIT or C#'s runtime environment that makes that call stack work differently?
Thanks for any pointers to documentation about this description of a call stack — there's plenty of documentation about how a traditional call stack works.