It seems uninitialized global variable is treated as weak symbol in Gcc. What is the reason behind this?
Is this what you meant?
weak.c
#include
int weak; /* global, weak, zero */
int main(void) {
printf("weak value is %d.\n", weak);
return 0;
}
strong.c
int weak = 42; /* global, strong, 42 */
Sample run
$ gcc weak.c $ ./a.out weak value is 0. $ gcc weak.c strong.c $ ./a.out weak value is 42.
The
This is a common extension, one that gcc uses (thanks Andrey).int weak; in weak.c is a declaration, not a definition. Or you may say it's a tentative definition. The real definition is in strong.c when that object file is linked in the final program or in weak.c otherwise.