Hello. I delve into the code with the help of a debugger, and try to understand by what principle GCC (C-compiler) places variables (local) on the stack. At first I thought that he pushes them in the same order:
that is, I met int auth_flag and pushes it onto the stack, the variable accordingly receives a larger address (since the stack grows in the direction of the lower addresses). Then password_buffer already gets the address less. But when I changed their places - nothing has changed:
auth_flag still gets the address more and (i.e., it is lower on the stack than password_buffer). I would think that this is how it should be, but I took this example from the book, and there, when the author swaps variables, they switch places and on the stack. Book for 2010, x32 architecture, possibly GCC younger.
Explain why this is happening, why the compiler does not allow you to choose the order of variables themselves, and how it “guides” when it allocates variables.
GCC version: 4.9.2