I am studying the behavior of global variables.
So far , I thought the multiple definition of global variables is an illegal way , and must get an error. But I got
Multiple external definitions of an object is undefined behavior in C. A common extension is to accept multiple definitions if they don't disagree (usually with same type and no initialization value).
C99 6.9p5 says:
If an identifier declared with external linkage is used in an expression (other than as part of the operand of a sizeof operator whose result is an integer constant), somewhere in the entire program there shall be exactly one external definition for the identifier; otherwise, there shall be no more than one"
and C99, 4.p2:
violation of a "shall" outside of a constraint implies UB