MISRAC2004-8.5_a
In this section:
Synopsis
(Required) There shall be no definitions of objects or functions in a header file.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
A global variable is declared in a header file. This check is identical to MISRAC++2008-3-1-1_a, MISRAC++2023-6.2.4_a.
Coding standards
- MISRA C++ 2008 3-1-1
(Required) It shall be possible to include any header file in multiple translation units without violating the One Definition Rule.
- MISRA C++ 2023 6.2.4
(Required) A header file shall not contain definitions of functions or objects that are non-inline and have external linkage
Code examples
The following code example fails the check and will give a warning:
/* global_def.h contains: int global_variable; */ #include "global_def.h"
The following code example passes the check and will not give a warning about this issue:
/* global_decl.h contains: extern int global_variable; */ #include "global_decl.h"