Versions Compared

Key

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

...

  • No linkage. If an identifier has no linkage, then any further declaration using the identifier declares something new, such as a new variable or a new type.

According to C99 to the C standard [ISO/IEC 9899:19992011], linkage is determined as follows:

If the declaration of a file scope identifier for an object or a function contains the storage class specifier static, the identifier has internal linkage.

For an identifier declared with the storage-class specifier extern in a scope in which a prior declaration of that identifier is visible, if the prior declaration specifies internal or external linkage, the linkage of the identifier at the later declaration is the same as the linkage specified at the prior declaration. If no prior declaration is visible, or if the prior declaration specifies no linkage, then the identifier has external linkage.

If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern. If the declaration of an identifier for an object has file scope and no storage-class specifier, its linkage is external.

The following identifiers have no linkage: an identifier declared to be anything other than an object or a function; an identifier declared to be a function parameter; a block scope identifier for an object declared without the storage-class specifier extern.

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

...

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) {
  /* ... */
}

...

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) {
  /* ... */
}

...

section

575 S

section

GCC

IF_DEF_IN_HEADER_DECL IF_MULTI_DECL

Tool

Version

Checker

Description

LDRA tool suite

Include Page
LDRA_V
LDRA_V
Section

Fully

Implemented section

implemented

Splint

Include Page
Splint_V
Splint_V

 

 

Section
Include Page
GCC_V
GCC_V

 

 

section

Klocwork

Include Page
Klocwork_V
Klocwork_V
Section

 

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

...

CERT C++ Secure Coding Standard: DCL36-CPP. Do not declare an identifier with conflicting linkage classifications

ISO/IEC 9899:19992011 Section 6.2.2, "Linkages of identifiers"

...