Keil Logo

Including Files Once Only

Header files often contain #include directives for other header files. This common practice can result in certain header files that are included more than once. If the header file defines structures or typedefs or if it defines program code or variables, the compiler may generate errors or warnings. Even if there are no erroneous side-effects, including a header file more than once is wasteful.

The standard technique to avoid header files from being included more than once is to enclose the contents of the header file in a preprocessor conditional. For example:


/* Header File Contents */


FILENAME_INCLUDED, when defined, indicates the header file FILENAME has been included.

Convention dictates that the macro name begins with '__' for system header files and should not begin with '_' for user header files. The macro name should contain the name of the header file and some additional text.

  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.