Main Content

MISRA C++:2008 Rule 16-2-4

The ', ", /* or // characters shall not occur in a header file name

Description

Rule Definition

The ', ", /* or // characters shall not occur in a header file name.

Rationale

You include header files in a source file by enclosing its name between the delimiters <> or "". Using the characters ', ", /*, or // between the delimiters < and > is undefined behavior. Using the characters ', /*, or // between the " delimiters also results in undefined behavior. Depending on your environment and compiler, using these characters in a header filer name might result in unexpected behavior.

Avoid the characters ', ", /*, or // in a header file name.

Polyspace Implementation

Polyspace® raises a violation of this rule if the name of a header file includes one of these characters:

  • '

  • "

  • /*

  • //

If you use the character " between the delimiter ", Polyspace interprets the portion of the header name between two successive " delimiters as the header file name. For instance, in this code,

#include "foo\".h"
Polyspace interprets foo\ as the header name. In such cases, Polyspace does not raise a violation of this rule, but because the compiler looks for a header file that does not exist, you might get a compilation warning.

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

expand all

#include<dummy'file> //Noncompliant
#include<dummy"file> //Noncompliant

#include<dummy/*file> //Noncompliant
#include<dummy//file> //Noncompliant

#include "dummy'file" //Noncompliant
#include "dummy file"   //Compliant

#include "dummy/*file" //Noncompliant
#include "dummy//file" //Noncompliant

In this example, Polyspace flags the use of the characters ', ", /*, or // in header file names.

Check Information

Group: Preprocessing Directives
Category: Required

Version History

Introduced in R2013b