Skip to content

Commit 30ef5b8

Browse files
authored
update code markdown for #include
1 parent 66792e4 commit 30ef5b8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

CppCoreGuidelines.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19190,7 +19190,7 @@ The [standard](http://eel.is/c++draft/cpp.include) provides flexibility for comp
1919019190
the two forms of `#include` selected using the angle (`<>`) or quoted (`""`) syntax. Vendors take
1919119191
advantage of this and use different search algorithms and methods for specifying the include path.
1919219192

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.
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.
1919419194

1919519195
##### Example
1919619196
// foo.cpp:
@@ -19200,7 +19200,7 @@ Nevertheless, the guidance is to use the quoted form for including files that ex
1920019200
#include "foo_utils/utils.h" // A file locally relative to foo.cpp, use "" form
1920119201

1920219202
##### 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. 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.
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.
1920419204

1920519205
Library creators should put their headers in a folder and have clients include those files using the relative path `#include <some_library/common.h>`
1920619206

0 commit comments

Comments
 (0)