In C and its derivatives,1 a header file consists of several handy data types and functions that extend the capability of our base code.

Header files will never contain executable code, and will never contain variable declarations. They may contain type definitions and function prototypes. The functions that are declared will be defined in a corresponding .cpp file that #include the header file. Then, whenever we invoke the header file, the functions are properly defined.

We invoke them through preprocessor directives. For instance:

#include <stdio.h>
#include <stdlib.h>

which searches for files within the standard library.

Note that we can define our own header files as well — this is especially useful for multi-file projects. We can instead #include inside quotation marks (which will search inside the current directory):

#include "bar.h"

List

A non-exhaustive list of important header files:

  • General libraries
  • Systems programming (mostly POSIX)
  • Specialised libraries
    • gmp.h — for high-precision computations.
    • queue.h — implements linked lists and queues.

Footnotes

  1. C++/Verilog/SystemVerilog