On 20-12-07 19:33, Luis Henriques wrote:
On Thu, Dec 20, 2007 at 01:03:35PM -0500, Ye ilho wrote:
[...]
I thought that I should get different value for the 2nd printf because
I have 'int a' in between but when I run it I am getting the same
value for both printfs.
Can anyone give me some insight on this? I am simply trying to get
stack pointer here. I am sorry for simple question and I tried to
google this but I was not good enough to find an answer. Thank you
very much in advance.
What is happening is that the compiler will not do what you think it
does, i.e., local variables are stored in the stack _but_ stack is set
at the beginning of the main function. When you declare a local
variable after the 1st printf, the compiler will allocate space for it
at the beginning of the main function.
Of course that, when calling printf the stack is also changed in order
to pass the printf parameters...
You can check exactly what is happening by using objdump ;)
Better yet, by gcc -S -- why disassemble when you needn't assemble? ;)
Rene.
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ