An identifier declared in different scopes or multiple times within the same scope can be made to refer to the same object or function by _linkage_. An identifier can be classified as _externally linked_, _internally linked_, or _not linked_. These three kinds of linkage have the following characteristics \[ [Kirch-Prinz 2002|AA. Bibliography#Kirch-Prinz 02]\]: Wiki Markup
- External linkage. An identifier with external linkage represents the same object or function throughout the entire program, that is, in all compilation units and libraries belonging to the program. The identifier is available to the linker. When a second declaration of the same identifier with external linkage occurs, the linker associates the identifier with the same object or function.
...
- 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 \ [[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\], 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.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
DCL36-C | medium | probable | medium | P8 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
| ||||||||||||
|
|
|
| ||||||||||||
|
|
|
| ||||||||||||
|
|
|
|
...
MISRA Rule 8.1
Bibliography
...
\[[Banahan 2003|AA. Bibliography#Banahan 03]\] [Section 8.2, "Declarations, Definitions and Accessibility"|http://publications.gbdirect.co.uk/c_book/chapter8/declarations_and_definitions.html]
\[Accessibility"
[Kirch-Prinz 2002|AA. Bibliography#Kirch-Prinz 02]\]
...
DCL35-C. Do not invoke a function using a type that does not match the function definition 02. Declarations and Initialization (DCL)