cpp: Header Files
1
1 2 Header Files
1 **************
1
1 A header file is a file containing C declarations and macro definitions
1 (⇒Macros) to be shared between several source files. You request
1 the use of a header file in your program by "including" it, with the C
1 preprocessing directive '#include'.
1
1 Header files serve two purposes.
1
1 * System header files declare the interfaces to parts of the
1 operating system. You include them in your program to supply the
1 definitions and declarations you need to invoke system calls and
1 libraries.
1
1 * Your own header files contain declarations for interfaces between
1 the source files of your program. Each time you have a group of
1 related declarations and macro definitions all or most of which are
1 needed in several different source files, it is a good idea to
1 create a header file for them.
1
1 Including a header file produces the same results as copying the
1 header file into each source file that needs it. Such copying would be
1 time-consuming and error-prone. With a header file, the related
1 declarations appear in only one place. If they need to be changed, they
1 can be changed in one place, and programs that include the header file
1 will automatically use the new version when next recompiled. The header
1 file eliminates the labor of finding and changing all the copies as well
1 as the risk that a failure to find one copy will result in
1 inconsistencies within a program.
1
1 In C, the usual convention is to give header files names that end
1 with '.h'. It is most portable to use only letters, digits, dashes, and
1 underscores in header file names, and at most one dot.
1
Menu