Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.INCL.INSIDE

Include directive preceded by a preprocessor output token.

MISRA C 2012 Rule 20.1: #include directives should only be preceded by preprocessordirectives or comments

C90 [Undefined 56], C99 [Undefined 96, 97]

Category: Advisory

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

The rule shall be applied to the contents of a file before preprocessing occurs.

Rationale

To 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.

Rationale

To 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