1.9 Header Files

Header files are text files included in a source file during compilation. To include a header file in a compilation, the #include preprocessor directive must be used in the source file. See Chapter 8 for more information on this directive. The entire header file, regardless of content, is substituted for the #include preprocessor directive.

A header file can contain other #include preprocessor directives to include another file. You can nest #include directives to any depth.

Header files can include any legal C source code. They are most often used to include external variable declarations, macro definitions, type definitions, and function declarations. Groups of logically related functions are commonly declared together in a header file, such as the C library input and output functions listed in the stdio.h header file. Header files traditionally have a .h suffix (stdio.h , for example).

The names of header files must not include the ', \, ", or /* characters, because the use of these punctuation characters in a header file is undefined.

When referenced in a program, header names are surrounded by angle brackets or double quotation marks, as shown in the following example:

#include <math.h>   /* or  */
#include "local.h"

Chapter 8 explains the difference between the two formats. The algorithm the compiler uses for finding the named files is discussed in Section B.37. Chapter 9 describes the library routines in each of the ANSI standard header files.


Previous Page | Next Page | Table of Contents | Index