LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   virtual address of local variables (http://www.linuxquestions.org/questions/programming-9/virtual-address-of-local-variables-564526/)

dale_chip 06-26-2007 02:52 AM

virtual address of local variables
 
hi ,
i was trying out this experiment.

int a;
int main()
{
int b;
printf("%p %p",&a,&b);
}

having compiled with gcc on RHEL whenever i run the code the address of a is same(which i was expecting) but of b it changes every time i run the code.

can anybody plz explain to me why is it so.
arn't virtual addresses to the start of stack segments fixed.(maybe it has got to do something about that).

jiml8 06-28-2007 10:56 AM

not sure...perhaps a, being global, winds up on the stack but b, being local, is defined in the module. In that case, you certainly wouldn't expect the system loader to load the module in the same place each time.


All times are GMT -5. The time now is 08:57 AM.