Keil Logo

#include

The #include directive causes the C preprocessor to include the contents of the specified file in the compilation before continuing with the rest of the current file. The #include directive may be used to specify two different types of header (or include) files: system header files and user header files.

System header files are included as follows:

#include <filename>

These include files are installed in the \INC\ folder. They are a part of the Keil development tools release and should not be modified. When a system header file is specified, the compiler searches for the file in the following folders in order:

  • Paths specified by the INCDIR directive.
  • Paths specified by the C51INC environment variable.

User header files are included as follows:

#include "filename"

These include files are user-created and may reside anywhere on your computer. When a user header file is specified, the compiler searches for the file in the following folders in order:

  • The current folder.
  • The source file folder.
  • Paths specified by the INCDIR directive.
  • Paths specified by the C51INC environment variable.

Note

  • Include files usually have an extension of .H indicating they are Header files. We recommend you use this standard for your user header files.
  • Typically, include files contain only variable declarations (not definitions), macro definitions, and definitions for Special Function Registers.
  • Include files may contain variable definitions. However, you must make certain that such a header file is only included in one C file in your project. Otherwise, multiple variables with the same name may be defined resulting in linker errors. We recommended that you do not define variables or functions in include files.
  • It is possible to begin or end a function in an include file. It is also possible to put function and variable definitions in include files. While these kinds of things are possible, they are very confusing and are not good coding habits to get into. Therefore, we do not recommend that you do them.

Refer to Header Files for a complete description of how to use include files in your C programs.

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.