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
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -19297,7 +19297,13 @@ The [standard](http://eel.is/c++draft/cpp.include) provides flexibility for comp
19297
19297
the two forms of `#include` selected using the angle (`<>`) or quoted (`""`) syntax. Vendors take
19298
19298
advantage of this and use different search algorithms and methods for specifying the include path.
19299
19299
19300
-
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 (from within the same component or project) and to use the angle bracket form everywhere else, where possible. This encourages being clear about the locality of the file relative to files that include it, or scenarios where the different search algorithm is required. 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 a header from the alternate search path (e.g. a header from another library or a common set of includes).
19300
+
Nevertheless, the guidance is to use the quoted form for including files that exist at a relative path
19301
+
to the file containing the `#include` statement (from within the same component or project) and to use
19302
+
the angle bracket form everywhere else, where possible. This encourages being clear about the locality
19303
+
of the file relative to files that include it, or scenarios where the different search algorithm is
19304
+
required. It makes it easy to understand at a glance whether a header is being included from a local
19305
+
relative file versus a standard library header or a header from the alternate search path (e.g. a header
19306
+
from another library or a common set of includes).
19301
19307
19302
19308
##### Example
19303
19309
@@ -19310,9 +19316,15 @@ Nevertheless, the guidance is to use the quoted form for including files that ex
19310
19316
19311
19317
##### Note
19312
19318
19313
-
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.
19319
+
Failing to follow this results in difficult to diagnose errors due to picking up the wrong file by
19320
+
incorrectly specifying the scope when it is included. For example, in a typical case where the `#include ""`
19321
+
search algorithm may search for a file existing at a local relative path first, then using this form to refer
19322
+
to a file that is not locally relative could mean that if a file ever comes into existence at the
19323
+
local relative path (e.g. the including file is moved to a new location), it will now be found ahead
19324
+
of the previous include file and the set of includes will have been changed in an unexpected way.
19314
19325
19315
-
Library creators should put their headers in a folder and have clients include those files using the relative path `#include <some_library/common.h>`
19326
+
Library creators should put their headers in a folder and have clients include those files using the
0 commit comments