Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: changed examples to match coding guidelines

...

Code Block
bgColor#FFCCCC
langc
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) {
  /* ... */
  return 0;
}

Implementation Details

Microsoft Visual Studio 2008 and later provide warnings for this code at the default warning level (/W3), but earlier versions do not warn even at the highest diagnostic levels. The GCC compiler generates a fatal diagnostic for the conflicting definitions of i2 and i5.

...

Code Block
bgColor#ccccff
langc
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) {
  /* ... */
  return 0;
}

Risk Assessment

Use of an identifier classified as both internally and externally linked causes undefined behavior.

...