The #include Directive

The #include directive inserts the contents of another file into your source file. The inserted file is called an include file or header file.

When the compiler encounters an #include, it searches for the file named in the directive. This directive makes QuickC look for the standard include file STDIO.H:

#include <stdio.h>

If the designated file is found, the compiler inserts its contents at the spot where the #include directive appears. Figure 7.1 illustrates a program SAMPLE.C that includes the file STDIO.H.

When QuickC compiles the SAMPLE.C program shown in Figure 7.1, it
inserts the contents of file STDIO.H into SAMPLE.C at the spot marked by the
#include directive.

Most include files contain commonly used declarations and definitions. Standard include files, supplied with QuickC, contain declarations and definitions for QuickC library routines. You can also write include files of your own.

Standard include files end with the .H file extension (STDIO.H is an example). You can use any extension for include files you create, but most programmers stick with the .H extension.

NOTE:

In some languages, it's common to put executable statements, as well as declarations and definitions, in include files. This practice is legal but not recommended in QuickC. Microsoft debugging tools such as the Microsoft CodeViewÒ debugger may not recognize executable statements in include files.

The #include directive doesn't support wildcards, so you can't insert a group of related files with a single directive. Each #include directive inserts only one file.

Include files can be nested. For instance, the source program SAMPLE.C might include a file named INOUT.H. The INOUT.H file, in turn, might contain a second #include directive that includes a file named KEYBOARD.H. Figure 7.2 illustrates this process.

Although it's rarely necessary to nest include files more than two or three levels, nesting may continue up to 10 levels.