MISRAC2012-Rule-20.1
In this section:
Synopsis
(Advisory) #include directives should only be preceded by preprocessor directives or comments.
Enabled by default
No
Severity/Certainty
Low/Low

Full description
#include directives were found that are not first in the source file. This check is identical to MISRAC2004-19.1, MISRAC++2008-16-0-1, MISRAC++2023-19.0.3.
Coding standards
- MISRA C:2004 19.1
(Advisory) #include statements in a file should only be preceded by other preprocessor directives or comments.
- MISRA C++ 2008 16-0-1
(Required) #include directives in a file shall only be preceded by other preprocessor directives or comments.
- MISRA C++ 2023 19.0.3
(Advisory) #include directives should only be preceded by preprocessor directives or comments
Code examples
The following code example fails the check and will give a warning:
int x;
#include <cstdio>
void example(void) {}
The following code example passes the check and will not give a warning about this issue:
#include <cstdio>
void example(void) {}