You ran into undefined behavior see N1570 6.9(p5) External definition
:
If an identifier declared with external linkage is used in an
expression (other than as part of the operand of a sizeof
or _Alignof
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.161)
As can be seen. The Standard allows 2 possibilities:
- exactly one definition
- no more than one definition.
This might depend on the linkage of libc
which itself is system dependent. In case you link libc
statically the linker will complain. In case of dynamic linking it have no reasong of complaining.
If you take a look at objdump
you will find plt
section like
898: e8 b3 fe ff ff callq 750 <gets@plt>
Anyway the behavior is undefined.