diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 6a2168c..8aaedf3 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -17298,18 +17298,29 @@ Flag `using namespace` at global scope in a header file. To avoid files being `#include`d several times. +In order to avoid include guard collisions, do not just name the guard after the filename. +Be sure to also include a key and good differentiator, such as the name of library or component +the header file is part of. + ##### Example // file foobar.h: - #ifndef FOOBAR_H - #define FOOBAR_H + #ifndef LIBRARY_FOOBAR_H + #define LIBRARY_FOOBAR_H // ... declarations ... - #endif // FOOBAR_H + #endif // LIBRARY_FOOBAR_H ##### Enforcement Flag `.h` files without `#include` guards. +##### Note + +Some implementations offer vendor extensions like `#pragma once` as alternative to include guards. +It is not standard and it is not portable. It injects the hosting machine's filesystem semantics +into your program, in addition to locking you down to a vendor. +Our recommendation is to write in ISO C++: See [rule P.2]((#Rp-Cplusplus). + ### SF.9: Avoid cyclic dependencies among source files ##### Reason