how to tell if the stack is growing from the top down or bottom up
Just now I came up with a method, the code is as follows, please advise:
void Stacktest () {int i = 0; int j = 0; int *PI = &i; int *PJ = &j; if (Pi < PJ) cout<< "Bottom Up" <<endl; else cout<< "Top Down" <<endl; }
The compiler does not really guarantee that I will be in front of J or behind ...
If you really want to judge it, it's better to use a function call:
BOOL Comparestack (int *p) {int newint; if (&newint < P) return true; Address decrement else return false; Address Increment} bool Getstackorder () {int oldint; Return Comparestack (&oldint); }
Compile options to turn off the inline pass parameter is a pointer to the local variable that was called at the previous level. The local variables of this level call must be stacked on top of the stack. That is to say, the address of the local variable of the two-tier call is compared
If it is limited to the x86 processor, do not judge, must be to the low address growth, not under the control of the application. Under X86 platform Linux, the address of memory allocated with functions such as malloc is growing upward. and the stack segment (note that stacks are stack, heap is heap, not the same thing) the address is growing downward.
To be simple to judge, the assembly code push, check the ESP register value is increased, or decreased.