devxlogo

What You Should Include in a Header File

What You Should Include in a Header File

A header file should begin and end with #include guards to guarantee that it’s not #included more than once during the same compilation session. A typical #include guard looks as follows:

 // from stdlib.h#ifndef STDLIB_INCLUDED // included for  the first time?#define STDLIB_INCLUDED// declarations, typedef's etc.#endif // close #include guard at the end of the file

size=3>
Inside the header file, you may insert function prototypes, structs declarations, #define macros, enum types, typedef’s, class declarations, extern declarations of global objects, template classes and functions, constants, certain #pragma directives that control the compilation process and similar macro directives. Note, however, that a header file should never have definitions (except for macros and templates). In other words, you shouldn’t implement functions and class member functions inside a header file (except for inline functions), nor should you create variables, arrays, and object or global variables in a header file.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist