-fno-common flag for GCC
Functions and initialized global variables get strong symbols. Uninitialized global variables get weak symbols
Rule 1: Multiple strong symbols (with same variable name) are not allowed.
Rule 2: Given a strong symbol and multiple weak symbols, choose the strong symbol.
Rule 3: Given multiple weak symbols, choose any of the weak symbols.
/*a.c*/
#include stdio.h
void b(void);
int x;
int main()
{
x = 2016;
b();
printf("x = %d ",x);
return 0;
}
/*b.c*/
#include stdio.h
int x;
void b()
{
x = 2017;
}
sdmrnv, 2019-08-15 [0.436ms, s]