MISRA C:2012 Rule 8.4
A compatible declaration shall be visible when an object or function with external linkage is defined
Description
Rule Definition
A compatible declaration shall be visible when an object or function with external linkage is defined.
Rationale
If a declaration is visible when an object or function is defined, it allows the compiler to check that the declaration and the definition are compatible.
This rule with MISRA C:2012 Rule 8.5
enforces the practice of
declaring an object (or function) in a header file and including the header file in
source files that define or use the object (or function).
Polyspace Implementation
The rule checker detects situations where:
An object or function is defined without a previous declaration.
There is a data type mismatch between the object or function declaration and definition. Such a mismatch also causes a compilation error.
The checker now flags tentative definitions (variables declared without an
extern
specifier and not explicitly defined). To avoid the
rule violation, declare the variable static
(defined in one file
only), or declare the variable extern
and follow the declaration
with a definition.
Additional Message in Report
Global definition of
variable_name
variable has no previous declaration.Function
function_name
has no visible compatible prototype at definition.
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