When a program is linked, the linker only cares about functions and global variables, and the linker recognizes them as symbols for linking. Note that function overloading in high-level languages is only a syntactic sugar, essentially a different function
Strong symbols: Functions and initialized global variables
Weak symbol: Uninitialized global variable
- Multiple strong symbols are not allowed. as follows, the compiler will error
//a.c中定义的全局变量iint i = 10;//b.c中定义的全局变量idouble i = 10;
- If you have 1 strong symbols and multiple weak symbols, select strong symbols. As below, will not error
//a.c中定义的全局变量iint i = 10;//b.c中定义的全局变量idouble i;
- If there are multiple weak symbols, randomly select one from them. As below, will not error
//a.c中定义的全局变量iint i;//b.c中定义的全局变量double i;
- It can be seen that the misuse of global variables is dangerous, so you should try to avoid global variables, or use static adornments.
Why should the C language use as few global variables as possible