.bss section and uninitialised variables

Gisle Grimen grimen@idi.ntnu.no
Wed Dec 22 13:57:00 GMT 2004


hello,

I am not an expert on linux or gcc, but i was wondering about one thing 
with variables and .bss section.

You have an relocatable elf file(.o) generated with gcc (3.3.5). My 
question is why the variable defined myvar (se simple src below) is not 
included in the .bss section so that it will be initialized to 0;

What happens is that i find a relocation entry and a symboltable entry for 
the variable, but it is not defined a section to which it belongs. If you 
initialize the variable with 0 (int myvar=0;) then everything is ok and it 
get put in the .bss section.

As i said i am not an expert in gcc and c, but does c allow such 
"undefined" variables? Java which i have much more experience with i know 
would initialise myvar with a 0 for me.

#src
# include <stdio.h>
int myvar;

int main(void){
 	printf("hello");
}


-Gisle



More information about the Gcc mailing list