Refer this Link Same Discussion
http://stackoverflow.com/questions/93039/where-are-static-variables-stored-in-c-c[
^]
The all Static Variables store in DATA SEGMENT MEMORY AREA.
Now Question is that if there are two function contain static variables having
same name then how compiler manages two var without falling in any ambiguity.
So see the TRANSFORMATION ON STATIC VARIABLE:-
See the practical explaination : Lets we have two function namely f1 and f2 as follows
void f1(void) { static int iX = 0; }
void f2(void) { static int iX = 0; }
During compiling of these codes , compiler converts variables in token called stag and defines as follows
.stabs "iX:f1",38,0,0,_iX { for the static varibale iX of function 1 }
.stabs "iX:f2",38,0,0,_iX { for the static varibale iX of function 2 }
For each process there is a symbol table which actually contains all variables and fuctions map.
The assembler transforms the stab into this symbol table entry in the `.o' file. The location is expressed as a data segment offset.
00000084 - 00 0000 STSYM iX :f1
00000088 - 00 0000 STSYM iX :f2
Symbol table is a compile-time data structure. It's not used during run time by statically typed languages. Formally, a symbol table
maps names into declarations (called attributes), such as mapping the variable name x to its type int. Moreever it stores :
1) for each type name, its type definition (eg. for the C type declaration typedef int* mytype, it maps the name
mytype to a data structure that represents the type int*).
2) for each variable name, its type. If the variable is an array, it also stores dimension information. It may also store
storage class, offset in activation record etc.
3)for each constant name, its type and value.
4) for each function and procedure, its formal parameter list and its output type. Each formal parameter must have name,
type, type of passing (by-reference or by-value), etc.
In the symbol table entry from the executable, the linker has made the relocatable address absolute and symbol table goes out of picture.
0000e0ba - 00 0000 STSYM iX :f1
0000e00c - 00 0000 STSYM iX :f2