]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/cpp/header-files.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / cpp / header-files.rst
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:: header file
7
8 .. _header-files:
9
10 Header Files
11 ------------
12
13 A header file is a file containing C declarations and macro definitions
14 (see :ref:`macros`) to be shared between several source files. You request
15 the use of a header file in your program by :dfn:`including` it, with the
16 C preprocessing directive :samp:`#include`.
17
18 Header files serve two purposes.
19
20 .. index:: system header files
21
22 * System header files declare the interfaces to parts of the operating
23 system. You include them in your program to supply the definitions and
24 declarations you need to invoke system calls and libraries.
25
26 * Your own header files contain declarations for interfaces between the
27 source files of your program. Each time you have a group of related
28 declarations and macro definitions all or most of which are needed in
29 several different source files, it is a good idea to create a header
30 file for them.
31
32 Including a header file produces the same results as copying the header
33 file into each source file that needs it. Such copying would be
34 time-consuming and error-prone. With a header file, the related
35 declarations appear in only one place. If they need to be changed, they
36 can be changed in one place, and programs that include the header file
37 will automatically use the new version when next recompiled. The header
38 file eliminates the labor of finding and changing all the copies as well
39 as the risk that a failure to find one copy will result in
40 inconsistencies within a program.
41
42 In C, the usual convention is to give header files names that end with
43 :samp:`.h`. It is most portable to use only letters, digits, dashes, and
44 underscores in header file names, and at most one dot.
45
46 .. toctree::
47 :maxdepth: 2
48
49 header-files/include-syntax
50 header-files/include-operation
51 header-files/search-path
52 header-files/once-only-headers
53 header-files/alternatives-to-wrapper-ifndef
54 header-files/computed-includes
55 header-files/wrapper-headers
56 header-files/system-headers