Quote:Original post by rip-off
C++ and C use the same rules for global variables.
Not really. C contains some frankly bizarre rules regarding globals. One of which that the OP seems to be relying on is the concept of tentative definitions. In C the following is legal at global scope:
int i;int i;
This creates one definition for i. This is further complicated by the fact that some compilers, for example some versions of gcc, place globals with only tentative definitions into the common segment of object files, which causes all but one to be discarded at link time. The closest C++ analog to this behavior is a static function variable in an inline function. AFAICT C's linkage rules for globals are supposed to be the same as C++'s but I'm not as familiar with the C standard as I am the C++ standard.