MISRA C++:2008 Rule 16-0-1
#include directives in a file shall only be preceded by other preprocessor directives or comments
Description
Rule Definition
#include directives in a file shall only be preceded by other preprocessor directives or comments.
Rationale
Grouping all #include preprocessor directives at the beginning of the source file makes the code more readable. #include directives might include header files where macros are defined. If you use such a macro before including its definition, you might encounter unexpected code behavior.
Polyspace Implementation
Polyspace® raises this defect when an #include
directive comes after
any code that is not a comment or preprocessor directive. Polyspace ignores code that is hidden by using conditional compilation directives such
as #if
or #ifdef
. Polyspace does not report a violation of this rule when an #include
directive is located within an extern "C"
block.
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: Preprocessing Directives |
Category: Required |