MISRA.INCL.INSIDEInclude directive preceded by a preprocessor output token.
MISRA C 2012 Rule 20.1: #include directives should only be preceded by preprocessordirectives or commentsC90 [Undefined 56], C99 [Undefined 96, 97] Category: Advisory Analysis: Decidable, Single Translation Unit Applies to: C90, C99 AmplificationThe rule shall be applied to the contents of a file before preprocessing occurs. RationaleTo aid code readability, all the #include directives in a particular code file should be grouped together near the top of the file. Additionally, using #include to include a standard header file within a declaration or definition, or using part of The Standard Library before the inclusion of the related standard header file leads to undefined behaviour. Example/* f.h */ xyz = 0; /* f.c */ int16_t #include "f.h" /* Non-compliant */ /* f1.c */ #define F1_MACRO #include "f1.h" /* Compliant */ #include "f2.h" /* Compliant */ int32_t i = 0; #include "f3.h" /* Non-compliant */ MISRA-C 2004 Rule 19.1 (advisory): #include statements in a file should only be preceded by other preprocessor directives or comments.Include directive preceded by a preprocessor output token. All the #include statements in a particular code file should be grouped together near the head of the file. The rule states that the only items which may precede a #include in a file are other preprocessor directives or comments. MISRA-C++ 2008 Rule 16-0-1 (required): #include directives in a file shall only be preceded by other preprocessor directives or comments.RationaleTo aid code readability, all the #include directives in a particular code file should be grouped together near the head of the file. The only items which may precede a #include in a file are other preprocessor directives or comments. Example#include <f1.h> // Compliant int32_t i; #include <f2.h> // Non-compliant |