MISRA C++:2008 Rule 3-1-1
It shall be possible to include any header file in multiple translation units without violating the One Definition Rule
Description
Rule Definition
It shall be possible to include any header file in multiple translation units without violating the One Definition Rule.1
Rationale
If a header file with variable or function definitions appears in multiple
inclusion paths, the header file violates the One Definition Rule possibly leading
to unpredictable behavior. For instance, a source file includes the header file
include.h
and another header file, which also includes
include.h
.
Polyspace Implementation
The rule checker flags variable and function definitions in header files.
Polyspace® reports violation of this rule in header files. In a nonheader source file, violation of this rule is not reported.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Basic Concepts |
Category: Required |
Version History
Introduced in R2013b
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.