Global vs. Local vars and .MAP 
Author Message
 Global vs. Local vars and .MAP

        I happen to be using Borland C/C++ 4.0, if that makes any
difference.  I'm wondering why global variables such as "int x;" appear
in my .MAP file, but local variables, say within main(), do not.  

Thanks in advance,
Doug



Mon, 22 Dec 1997 03:00:00 GMT  
 Global vs. Local vars and .MAP
The local variables are allocated on the stack, while the Global and
Statics are actually in the DATA area of the program.

        I happen to be using Borland C/C++ 4.0, if that makes any
difference.  I'm wondering why global variables such as "int x;" appear
in my .MAP file, but local variables, say within main(), do not.  

Thanks in advance,
Doug



Mon, 22 Dec 1997 03:00:00 GMT  
 Global vs. Local vars and .MAP

Quote:

>    I happen to be using Borland C/C++ 4.0, if that makes any
>difference.  I'm wondering why global variables such as "int x;" appear
>in my .MAP file, but local variables, say within main(), do not.  

>Thanks in advance,
>Doug

A global variable is allocated space in a data segment and is visible
to all modules and therefore has an assigned address that does not
change thourghout the life of the program.

A variable defined inside a function (like main) is a dynamic variable
and is allocated on the stack when the function is entered and destroyed
when the function is exited. Therefore the address of the local variable
is not known at compile or link time, only at run time, and it may not
have the same address or sucessive calls to the function



Tue, 23 Dec 1997 03:00:00 GMT  
 Global vs. Local vars and .MAP

Quote:

>The local variables are allocated on the stack, while the Global and
>Statics are actually in the DATA area of the program.

>    I happen to be using Borland C/C++ 4.0, if that makes any
>difference.  I'm wondering why global variables such as "int x;" appear
>in my .MAP file, but local variables, say within main(), do not.  

>Thanks in advance,
>Doug

Also...
   You'll also notice that statics don't show up in the .MAP file. This is
because the .MAP file is a product of the linker, which is concerned with
combining object modules together to form a complete program. It only cares
about variables that are declared public (in assembly). These public vars
are visible between object modules. These are the variables that show up
in the .MAP file. (Global vars in C are public in asm.) Static variables, on
the other hand, are known only inside the module in which they are defined.
They are NOT declared public in assembly, so they don't show up in the map.

Randy Beckwith
Optimization Technology, Inc. (OTI)
Huntsville, Alabama



Tue, 23 Dec 1997 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. global vars vs: local vars

2. global vs local vars

3. how to access local and global vars in a function

4. static local variables vs global variables

5. ? global vs local structures...

6. global vs local

7. Watching global vs. local variable w/ same name

8. global vs. local

9. global vs local states

10. basic question about pointers and local vars

11. VC6 SP3 debugger, local vars not recognized

12. global/static vars inside loops

 

 
Powered by phpBB® Forum Software