Functions and objects should not be defined with external linkage if they are referenced in only one translation unit
This checker is deactivated in a default Polyspace® as You Code analysis. See Checkers Deactivated in Polyspace as You Code Default Analysis (Polyspace Bug Finder Access).
Functions and objects should not be defined with external linkage if they are referenced in only one translation unit.
Compliance with this rule avoids confusion between your identifier and an identical identifier in another translation unit or library. If you restrict or reduce the visibility of an object by giving it internal linkage or no linkage, you or someone else is less likely to access the object inadvertently.
The rule checker flags:
Objects that are defined at file scope without the
static specifier but used only in one
file.
Functions that are defined without the static
specifier but called only in one file.
If you intend to use the object or function in one file only, declare it static.
If your code does not contain a main function and you use
options such as Variables to
initialize (-main-generator-writes-variables) with value custom
to explicitly specify a set of variables to initialize, the checker does not flag
those variables. The checker assumes that in a real application, the file containing
the main must initialize the variables in addition to any file
that currently uses them. Therefore, the variables are used in more than one
translation unit.
Polyspace Bug Finder™ and Polyspace Code Prover™ check this coding rule differently. The analyses can produce different results.
Variable variable_name should
have internal linkage.
Function function_name should
have internal linkage.
If you expect a rule violation but do not see it, refer to Coding Standard Violations Not Displayed.
| Group: Declarations and Definitions |
| Category: Advisory |
| AGC Category: Advisory |