You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CppCoreGuidelines.md
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -19190,17 +19190,17 @@ The [standard](http://eel.is/c++draft/cpp.include) provides flexibility for comp
19190
19190
the two forms of `#include` selected using the angle (`<>`) or quoted (`""`) syntax. Vendors take
19191
19191
advantage of this and use different search algorithms and methods for specifying the include path.
19192
19192
19193
-
Nevertheless, the guidance is to use quoted form for including files that exist at a relative path to the file containing the #include statement and to use the angle bracket form everywhere else where possible. This supports being clear about the locality of the header relative to files that includes it or in scenarios where the different search algorithm is required. For example, it makes it easy to determine at a glance whether a header is being included from a local relative file versus a standard library header or an external header from another project.
19193
+
Nevertheless, the guidance is to use the quoted form for including files that exist at a relative path to the file containing the '#include statement' and to use the angle bracket form everywhere else, where possible. This encourages being clear about the locality of the header relative to files that include it, or scenarios where the different search algorithm is required. For example, it makes it easy to understand at a glance whether a header is being included from a local relative file versus a standard library header or an external header from another project.
19194
19194
19195
19195
##### Example
19196
-
foo.cpp:
19197
-
#include <string> // From the standard library, required form
19198
-
#include <some_library/common.h> //A non-local include file from an external library, use the <> form
19199
-
#include "foo.h" // A local file relative to foo.cpp, use "" form
19200
-
#include "utils/foo_utils.h" // A local file relative to foo.cpp, use "" form
19196
+
// foo.cpp:
19197
+
#include <string> // From the standard library, requires the <> form
19198
+
#include <some_library/common.h> // A file that is not locally relative, included from an external project; use the <> form
19199
+
#include "foo.h" // A file locally relative to foo.cpp, use the "" form
19200
+
#include "foo_utils/utils.h" // A file locally relative to foo.cpp, use "" form
19201
19201
19202
19202
##### Note
19203
-
Failing to follow this results in difficult to diagnose errors due to picking up the wrong file by incorrectly specifying the scope when it is included.
19203
+
Failing to follow this results in difficult to diagnose errors due to picking up the wrong file by incorrectly specifying the scope when it is included. For example, in a typical case where the '#include ""' search algorithm may search for a file existing at a local relative path first, then using this form to refer to a file that is not locally relative could mean that if a file ever comes into existence at the local relative path (e.g. the including file is moved to a new location), it will now be found ahead of the previous include file and the set of includes will have been changed in an unexpected way.
19204
19204
19205
19205
Library creators should put their headers in a folder and have clients include those files using the relative path `#include <some_library/common.h>`
0 commit comments