C and C++


LANG.PREPROC.CBI : Code Before #include

Summary

Code was placed before an #include directive.

Properties

Class Name Code Before #include
Significance style
Mnemonic LANG.PREPROC.CBI
Categories
MisraC2023 MisraC2023:20.1 #include directives should only be preceded by preprocessor directives or comments
Misra2012 Misra2012:20.1 #include directives should only be preceded by preprocessor directives or comments
Misra2004 Misra2004:19.1 #include statements in a file should only be preceded by other preprocessor directives or comments
AUTOSARC++14 AUTOSARC++14:M16-0-1 #include directives in a file shall only be preceded by other pre-processor directives or comments.
MisraC++2008 MisraC++2008:16-0-1 #include directives in a file shall only be preceded by preprocessor directives or comments.
MisraC++2023 MisraC++2023:19.0.3 #include directives should only be preceded by preprocessor directives or comments
CWE CWE:710 Improper Adherence to Coding Standards
JPL JPL:31 Do not place code or declarations before an #include directive.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Code Before #include"

Example

#include <stdlib.h>

static const int errflag=0xdeadbeef; /* 'Code Before #include' warning issued here */

#include <stdio.h>

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.