LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 06-26-2007, 03:52 AM   #1
dale_chip
Member
 
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
jiml8
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.
 
  


Reply


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) skd.tech Linux - Kernel 7 07-25-2006 12:13 AM
Local vs Global variables wujee Programming 1 03-12-2005 12:43 AM


All times are GMT -5. The time now is 10:24 PM.

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