...
In this noncompliant code example, i2
and i5
are defined as having both internal and external linkage. Future use of either identifier results in undefined behavior.
Code Block | ||||
---|---|---|---|---|
| ||||
int i1 = 10; /* definition, external linkage */ static int i2 = 20; /* definition, internal linkage */ extern int i3 = 30; /* definition, external linkage */ int i4; /* tentative definition, external linkage */ static int i5; /* tentative definition, internal linkage */ int i1; /* valid tentative definition */ int i2; /* not valid, linkage disagreement with previous */ int i3; /* valid tentative definition */ int i4; /* valid tentative definition */ int i5; /* not valid, linkage disagreement with previous */ int main(void) { /* ... */ } |
...
This compliant solution does not include conflicting definitions.
Code Block | ||||
---|---|---|---|---|
| ||||
int i1 = 10; /* definition, external linkage */ static int i2 = 20; /* definition, internal linkage */ extern int i3 = 30; /* definition, external linkage */ int i4; /* tentative definition, external linkage */ static int i5; /* tentative definition, internal linkage */ int main(void) { /* ... */ } |
...