Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Identify undefined behavior

...

In this noncompliant code example, i2 and i5 are defined as having both internal and external linkage. Future use of either identifier results in in undefined behavior 8.

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;  /* Undefined, linkage disagreement with previous */
int i3;  /* Valid tentative definition */
int i4;  /* Valid tentative definition */
int i5;  /* Undefined, linkage disagreement with previous */

int main(void) {
  /* ... */
  return 0;
}

...

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

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

DCL36-C

Medium

Probable

Medium

P8

L2

...