Altera_Forum
Honored Contributor
11 years agoHow to find memory location of static linked variables with equal names
Hi all,
A simple example uses two static variables named "aa": static int told=0;
...
start_endless_loop: //------------- endless loop
if (alt_nticks() > told) {
told = alt_nticks() + 1000;
static int aa=0;
if (aa < 5) {
printf("%d ",aa);
aa++;
for (i=0; i<10; i++) {
static int aa=1000;
aa++;
if (i==9) printf("%d\n",aa);
}
}
}
....
goto start_endless_loop; //------- endless Loop The console shows: --- Quote Start --- 0 1010 1 1020 2 1030 3 1040 4 1050 --- Quote End --- To resolve the adresses of the two "aa"s in the symbol table I used the Nios Command Shell with the command "readelf -s" : --- Quote Start --- ... 122: 002167a0 4 OBJECT LOCAL DEFAULT 6 aa.5198 ... 132: 002166f0 4 OBJECT LOCAL DEFAULT 5 aa.5199 ... --- Quote End --- It shows that the compiler has generated different variables for each "aa" The memory shows: --- Quote Start --- 0x002167a0: 5 0x002166f0: 1050 --- Quote End --- The question is: How does the compiler/linker generate the internal variables "aa.5198" and "aa.5199" and how can I get the location of the variables in the source code from the compiler-added numbers? Kind regards