Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-26-2007, 03:52 AM   #1
Registered: Jun 2007
Location: India
Posts: 41

Rep: Reputation: 15
Question 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).
Old 06-28-2007, 11:56 AM   #2
Senior Member
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
local mail distribution already having virtual address on isp faisalusuf Linux - Server 2 06-13-2007 02:03 AM
how to find physical address of kernel virtual address kushneeraj Programming 0 10-20-2006 08:29 PM
API for mapping Physical Address to Virtual Address Lakshman_smt Linux - Software 2 10-15-2006 10:08 PM
Memory Mapping (same physical address = virtual address) Linux - Kernel 7 07-25-2006 12:13 AM
Local vs Global variables wujee Programming 1 03-12-2005 12:43 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:23 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration