If you want to parse and process any language, you probably need to read some text books first.
E.g.
C-Programming Language[
^], or
C11 Language Draft[
^], etc.
E.g. the latter specifies the
#include
semantics as follows:
[...]
6.10.2 Source file inclusion
- Constraints
A #include
directive shall identify a header or source file that can be processed by the
implementation. - Semantics
A preprocessing directive of the form
# include <h-char-sequence> new-line
searches a sequence of implementation-defined places for a header identified uniquely by
the specified sequence between the <
and >
delimiters, and causes the replacement of that
directive by the entire contents of the header. How the places are specified or the header
identified is implementation-defined. - A preprocessing directive of the form
# include "q-char-sequence" new-line
causes the replacement of that directive by the entire contents of the source file identified
by the specified sequence between the "
delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search
fails, the directive is reprocessed as if it read
# include <h-char-sequence> new-line
with the identical contained sequence (including > characters, if any) from the original
directive. [...]
Furthermore, some fallback is defined to avoid infinte inclusion loop (e.g. an implementaiton is not required to support more than 15 nested including levels, etc.).
Usually, including
<...>
searches first for system headers,
"..."
searches in the provided
-I...
paths first. But as stated above, it is implementation dependent. Check your target compiler for the implemented semantics of these includes.
Please note that the
#include
does
not add the files in some "magic" list - it simply replaces the
#include
line literally by the content of the referenced file (as if you had written the content of the included file at the location of the
#include
line).
Cheers
Andi
PS: if you use with gcc the -E -C options, you see the effect of the inclusion and other preprocessing.