AUTOSAR C++14 Rule M16-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 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 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, Automated |