Hi,
i have some questions mostly regarding the memory segments... Can any one help me out..
1. During a function call in C, where is the return value of the called function stored.. This is mainly a question came when i was thinking of steps during a function call.
The steps i have in my mind are,
a) store the return address of calling function in stack
b) create a new stack frame for the called function. store local variables in stack
c) return to the called function after operation is finished.
d) delete stack frame and continue execution
Here in the step c, suppose i am returning a value like
return (a+b);
where both a and b are my local variables in the called function, how the caller gets this value to his function. The stack frames of both these are different.
Or
Where exactly the value of a+b is stored? In stack? If yes in which frame????
I am mainly confused about the process how the caller gets the return value..
2nd question
2. Suppose i have a global static variable and a local static variable
I am pasting the code here,
#include <stdio.h>
static int myvar= 0 ;
int main()
{
call();
printf("My var in main is %d \n",myvar);
return 1;
}
int call()
{
static int myvar = 1;
printf("My var is %d \n",myvar);
}
just to know, how the compiler distinguishes these variables, i took objdump of these code after building it with gcc...
it showed
080495b4 l O .bss 00000004 myvar
080495ac l O .data 00000004 myvar.1784
here myvar is my global static and myvar.1784 is my local static.
I want to know how my local static variable is in .data segment and my global static is in .bss specifically?
and what about that peculiar .1784 naming in that local static variable...
can anybody guide me?