MISRA C:2012 Rule 8.5
An external object or function shall be declared once in one and only one file
Description
Rule Definition
An external object or function shall be declared once in one and only one file.
Rationale
Declaring an identifier in a header file enables you to include the header file in any translation unit where the identifier is defined or used. Modularizing the declarations in header files helps maintain consistency between:
The declaration and the definition.
The declarations in different translation units.
The rule enforces the practice of declaring external objects or functions in header files.
Polyspace Implementation
The rule checker checks explicit and implicit extern
declarations
(tentative definitions are ignored). The checker flags variables or functions:
Declared
extern
in a nonheader fileDeclared multiple times, for instance, once in a header and once in a nonheader file.
This checker:
Ignores compiler-specific, nonportable ways of overriding function declarations, such as
pragma weak
or__attribute__((weak))
.Ignores typedefs and function declarations that are not used in the code.
Considers redeclaration as a rule violation. For instance, if you declare a weak symbol in your code, and then redeclare the symbol later, Polyspace® reports a violation. If you do not want to fix such violations, add a comment to your result or code to avoid another review. See:
Address Results in Polyspace User Interface Through Bug Fixes or Justifications if you review results in the Polyspace user interface.
Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access) if you review results in a web browser.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Declarations and Definitions |
Category: Required |
AGC Category: Advisory |
Version History
Introduced in R2014b