4 ms·
1. Unless C's variable definition rules are completely different from C++'s, int i; is a full definition, not a declaration. If both definitions appear at the s
by E6300 10y ago
1. Unless C's variable definition rules are completely different from C++'s, int i; is a full definition, not a declaration. If both definitions appear at the same scope (e.g. global), this will cause either a compiler error or a linker error. A variable declaration would be extern int i;
- khedoros1 10y agoC's variable definition rules are different from C++'s. gcc happily compiles those two lines, g++ exits with the "redefinition" error.
- E6300 10y agoThat was unexpected.
- shabbyrobe 10y agoSaid every C programmer ever!
- caf 10y agoYes, in C a plain int i; at file scope is a tentative definition - if, by the end of the compilation unit, no definition has been seen, one of them will become a definition, otherwise it is just a declaration. On the other hand, this: int i = 0; is a definition, and you can't have two of those.