Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

An Linkage can make an identifier declared in different scopes or declared multiple times within the same scope can be made to refer to the same object or function by linkage. An identifier can be . Identifiers are classified as externally linked, internally linked, or not linked. These three kinds of linkage have the following characteristics [Kirch-Prinz 2002]:

...

According to the C Standard, subclause 6.2.2 [ISO/IEC 9899:2011], linkage is determined as follows:

...

Use of an identifier (within one translation unit) classified as both internally and externally linked causes undefined behavior. See (see also undefined behavior 8 in Appendix J of the C Standard, Annex J). A translation unit includes the source file together with its headers and all source files included via the preprocessing directive #include.

The following table identifies the linkage assigned to an object that is declared twice in a single translation unit. The column designates the first declaration, and the row designates the redeclaration.

1st \ 2nd

static

No Linkage

extern

static

Internal

Undefined

Internal

No Linkage

Undefined

No Linkage

External

extern

Undefined

Undefined

External

Image Added

Noncompliant Code Example

...

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

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

...

...