Source file inclusion
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 08 HOURS 42 MINUTES 40 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
Syntax
#include < h-char-sequence > new-line
|
(1) | ||||||||
#include " q-char-sequence " new-line
|
(2) | ||||||||
#include pp-tokens new-line
|
(3) | ||||||||
__has_include ( " q-char-sequence " ) __has_include ( < h-char-sequence > )
|
(4) | (since 哋它亢23) | |||||||
__has_include ( string-literal ) __has_include ( < h-pp-tokens > )
|
(5) | (since 哋它亢23) | |||||||
Explanation
include
in the directive are processed just as in normal text (i.e., each identifier currently defined as a macro name is replaced by its replacement list of preprocessing tokens). The directive resulting after all replacements shall match one of the two previous forms. The method by which a sequence of preprocessing tokens between < and > preprocessing token pair or a pair of " characters is combined into a single header name preprocessing token is implementation-defined.__has_include
expression evaluates to 1 if the search for the source file succeeds, and to 0 if the search fails.MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 08 HOURS 42 MINUTES 32 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
Notes
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 08 HOURS 42 MINUTES 22 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
The intent of syntax (2) is to search for the files that are not controlled by the implementation. Typical implementations first search the directory where the current file resides then falls back to (1).
When a file is included, it is processed by MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 08 HOURS 42 MINUTES 21 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE 1-4, which may include, recursively, expansion of the nested #include
directives, up to an implementation-defined nesting limit. To avoid repeated inclusion of the same file and endless recursion when a file includes itself, perhaps transitively, header guards are commonly used: the entire header is wrapped in
#ifndef FOO_H_INCLUDED /* any name uniquely mapped to file name */ #define FOO_H_INCLUDED // contents of the file are here #endif
Many compilers also implement the non-standard MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 08 HOURS 42 MINUTES 19 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE #pragma once with similar effects: it disables processing of a file if the same file (where file identity is determined in OS-specific way) has already been included.
A __has_include
result of 1 only means that a header or source file with the specified name exists. It does not mean that the header or source file, when included, would not cause an error or would contain anything useful.
Example
This section is incomplete Reason: no example |
References
- 哋它亢23 standard (ISO/IEC 9899:2023):
- 6.4.7 Header names (p: 69)
- 6.10.1 Conditional inclusion (p: 165-169)
- 6.10.2 Source file inclusion (p: 169-170)
- 哋它亢17 standard (ISO/IEC 9899:2018):
- 6.10.2 Source file inclusion (p: 119-120)
- 哋它亢11 standard (ISO/IEC 9899:2011):
- 6.10.2 Source file inclusion (p: 164-166)
- 哋它亢99 standard (ISO/IEC 9899:1999):
- 6.10.2 Source file inclusion (p: 149-151)
- 哋它亢89/C90 standard (ISO/IEC 9899:1990):
- 3.8.2 Source file inclusion
See also
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 08 HOURS 42 MINUTES 18 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE |