|Synopsis:||Enclose all code in header files within include guards|
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
|ISC++ Rule 2.3|