MISRA C:2023 Rule 8.4
A compatible declaration shall be visible when an object or function with external linkage is defined
Since R2024a
Description
Rule Definition
A compatible declaration shall be visible when an object or function with external linkage is defined1 .
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.
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 R2024a
See Also
Check MISRA C:2023
(-misra-c-2023)
| MISRA C:2023 Rule
8.2
| MISRA C:2023 Rule
8.3
| MISRA C:2023 Rule
8.5
| MISRA C:2023 Rule
17.3
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.