Y
Hacker News
new
|
ask
|
show
|
jobs
by
khedoros1
3410 days ago
C's variable definition rules are different from C++'s. gcc happily compiles those two lines, g++ exits with the "redefinition" error.
2 comments
caf
3410 days ago
Yes, 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.
link
E6300
3410 days ago
That was unexpected.
link
shabbyrobe
3410 days ago
Said every C programmer ever!
link
On the other hand, this:
is a definition, and you can't have two of those.