]>
Commit | Line | Data |
---|---|---|
c63539ff ML |
1 | .. |
2 | Copyright 1988-2022 Free Software Foundation, Inc. | |
3 | This is part of the GCC manual. | |
4 | For copying conditions, see the copyright.rst file. | |
5 | ||
6 | .. index:: #include | |
7 | ||
8 | .. _include-syntax: | |
9 | ||
10 | Include Syntax | |
11 | ************** | |
12 | ||
13 | Both user and system header files are included using the preprocessing | |
14 | directive :samp:`#include`. It has two variants: | |
15 | ||
16 | :samp:`#include <{file}>` | |
17 | This variant is used for system header files. It searches for a file | |
18 | named :samp:`{file}` in a standard list of system directories. You can prepend | |
19 | directories to this list with the :option:`-I` option (see :ref:`invocation`). | |
20 | ||
21 | :samp:`#include "{file}"` | |
22 | This variant is used for header files of your own program. It | |
23 | searches for a file named :samp:`{file}` first in the directory containing | |
24 | the current file, then in the quote directories and then the same | |
25 | directories used for ``<file>``. You can prepend directories | |
26 | to the list of quote directories with the :option:`-iquote` option. | |
27 | ||
28 | The argument of :samp:`#include`, whether delimited with quote marks or | |
29 | angle brackets, behaves like a string constant in that comments are not | |
30 | recognized, and macro names are not expanded. Thus, ``#include | |
31 | <x/*y>`` specifies inclusion of a system header file named :samp:`x/*y`. | |
32 | ||
33 | However, if backslashes occur within :samp:`{file}`, they are considered | |
34 | ordinary text characters, not escape characters. None of the character | |
35 | escape sequences appropriate to string constants in C are processed. | |
36 | Thus, ``#include "x\n\\y"`` specifies a filename containing three | |
37 | backslashes. (Some systems interpret :samp:`\\` as a pathname separator. | |
38 | All of these also interpret :samp:`/` the same way. It is most portable | |
39 | to use only :samp:`/`.) | |
40 | ||
41 | It is an error if there is anything (other than comments) on the line | |
3ed1b4ce | 42 | after the file name. |