...
- whose declaration contains the storage-class specifier
extern
, where no prior declaration of that identifier is visible. - for a function whose declaration contains no storage-class specifier.
- for an object with file scope whose declaration contains no storage-class specifier.
An identifier that is classified as internally linked includes identifiers whose declaration contains the storage-class specifier static
.
An identifer identifier that is classified as not-linked include:
- 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
.
If a prior declaration is visible and has no linkage, the latter declaration is externally linked. If a prior declaration is visible and has either internal or external linkage, the latter declaration is classified with the same linkage as the prior declaration.
Use of an identifier (within one translational unit) classified as both internally and externally linked causes undefined behavior. A translational unit includes the source file together with its headers, and all source files included via the preprocessing directive #include
.
Wiki Markup |
---|
This recommendation is a weaker recommendation than \[[DCL01-A|DCL01-A. Do not reuse variable names in sub-scopes]]. |
Non-Compliant Code Example
...
Code Block | ||
---|---|---|
| ||
int x; /* externally linked */ int main(void) { static int x; /* internally linked */ /* use of identifier x results in undefined behavior */ } |
Compliant Solution
More descriptive identifier names are used, avoiding This compliant solution uses different (and more descriptive) identifiers to avoid any conflicts.
Code Block | ||
---|---|---|
| ||
int external_x; /* externally linked */ int main(void) { static int internal_x; /* internally linked */ /* we're good to go */ } |
...