#include Directive

Preprocessor directive that inserts the contents of the specified file into the source program at the point where the directive appears.

#include "filename"
#include <filename>

Parameters

Item Description
filename Filename of the file to include, optionally preceded by a directory specification. The filename must specify an existing file.

Remarks

The #include directive causes replacement of the directive by the entire contents of the specified file. The preprocessor stops searching as soon as it finds a file with the specified name; if you specify a complete, unambiguous path specification for the file, the preprocessor searches only the specified path.

Note

The Effect-Compiler Tool has a built-in include handler using the /I switch. However, when executing the compiler from the API, you can provide a customized include handler by implementing the ID3DXInclude interface.

The difference between the two syntax forms is the order in which the preprocessor searches for header files when the path is incompletely specified, as shown in the following table.

Syntax form Preprocessor search pattern
#include "filename" Searches for the include file:
  1. in the same directory as the file that contains the #include directive.
  2. in the directories of any files that contain a #include directive for the file that contains the #include directive.
  3. in paths specified by the /I compiler option, in the order in which they are listed.
  4. in paths specified by the INCLUDE environment variable, in the order in which they are listed.

    NOTE:
    The INCLUDE environment variable is ignored in an development environment. Refer to your development environment's documentation for information about how to set the include paths for your project.


#include <filename> Searches for the include file:
  1. in paths specified by the /I compiler option, in the order in which they are listed.
  2. in paths specified by the INCLUDE environment variable, in the order in which they are listed.

    NOTE:
    The INCLUDE environment variable is ignored in an development environment. Refer to your development environment's documentation for information about how to set the include paths for your project.


Examples

The following example causes the preprocessor to replace the #include directive with the contents of stdio.h. Because the example uses the angle bracket format, the preprocessor will search for the file only in the directories listed by the /I compiler option and the INCLUDE environment variable.

#include <stdio.h>

See also