stack memory layout in C -
I try to understand the stack memory layout in C by compiling the following code and inspecting the address in GDB. I only record at least important points, the higher one is equal to the output
print \ u & amp; A is generated using a Here is a simple test code:
zero test (int a, int b) {int c = a ; Int d = b; Printf ("% d,% d \ n", c, d); } Int main () {int x = 1; Int y = 2; Test (x, y); Return 0; } I have the following results, and B: 6808 and A: 6812
& Amp; Amp; C: 6824 & amp; D: 6828
$ rbp: 6832 (frame indicator).
I am confused with regard to local variables, the parameters should not work sitting on the high memory address, can anyone explain this in detail? Thank you.
Edit: If I print the memory like this:
printf ("& amp; a:% p, & amp; b:% p \ n ", (& Amp; amp; nbsp;), (and b)); Printf ("& amp; c:% p, & d:% p \ n", (& amp; c), (& amp; D)); I found
& amp; A: 0x7fff4737687c, & amp; B: 0x7fff47376878 & amp; C: 0x7fff47376888, & amp; D: 0x7fff4737688c This BACD is in sequence, there is an 8-byte difference between the beginning of C and the end of C. I think its return will be known? According to the flow of a function, the first arguments have been allocated and then the internal argument.
Your concern is based on the estimate that the stack increases (which is not necessary).
Please follow the following link to understand more:
Comments
Post a Comment