...
1st \ 2nd |
| none |
|
|---|---|---|---|
| internalInternal | undefinedUndefined | internalInternal |
none | undefinedUndefined | externalExternalexternal | External |
| undefinedUndefined | externalExternalexternal | External |
Noncompliant Code Example
...
Microsoft Visual Studio 2008 and later provide warnings for this code at the default warning level (/W3), however 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.
...
This compliant solution does not include conflicting definitions.:
| Code Block | ||||
|---|---|---|---|---|
| ||||
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) {
/* ... */
}
|
...
Tool | Version | Checker | Description | GCC | includeGCC_V | GCC_V | |||
|---|---|---|---|---|---|---|---|---|---|
|
| Coverity | 6.5 | LINKAGE_CONFLICT | Fully implemented | ||||
| intllnkg | Fully implemented | |||||||
GCC |
|
|
| ||||||
| IF_DEF_IN_HEADER_DECL IF_MULTI_DECL |
| |||||||
| 575 S | Fully implemented | |||||||
Splint |
|
|
| ||||||
| PRQA QA-C |
| 0625 (U) | Fully implemented |
...
| CERT C++ Secure Coding Standard | DCL36-CPP. Do not declare an identifier with conflicting linkage classifications |
| MISRA-C | Rule 8. 12 (required) |
Bibliography
| [Banahan 2003] | Section 8.2, "Declarations, Definitions and Accessibility" |
| [ISO/IEC 9899:2011] | Section 6.2.2, "Linkages of Identifiers" |
| [Kirch-Prinz 2002] |
...