From 52aa9ba997ef9ce5495d231492fe75e2a59ed93b Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Mon, 8 May 2017 10:50:03 -0700 Subject: [PATCH] Fix #903. --- CppCoreGuidelines.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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