TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  ORG#001Checked automatically with code checker

Synopsis:Enclose all code in header files within include guards
Severity Level:3
Category:Code Organization


This minimizes build time and prevents compilation problems due to redefinitions.

Alternative 1: include guards:

Adding the following preprocessor statements at the beginning of the header file prevents multiple inclusion:

#ifndef FILENAME_H
#define FILENAME_H

And the following statement at the end:

#endif // FILENAME_H

See [STY#024] for the naming of these guards.

Alternative 2: #pragma once:

Although most modern compilers support this compiler directive, "#pragma once" is not an ISO standard and thus not portable. It's nevertheless allowed to use "pragma once" because

  • it never leads to name clashes
  • it's less susceptible to typo's
#pragma once

Literature References:
ISC++ Rule 2.3