Header file

from Wikipedia, the free encyclopedia

In programming , especially in the programming languages C ++ and C , a header file is a text file that contains declarations and other components of the source text . Source text that is located in a header file is generally intended for use in several programs or several parts of a program.

Task of a header file

To simplify the handling of medium-sized or large programs, programs are divided into several so-called translation units . Associated source text components are summarized in files, the so-called header files, which can be referenced by other files by being incorporated into the source text. The header files thus form the interface between the individual units.

The organization in header files also avoids recompilation of the programs or program parts accessing the interface when the implementation is changed .

In program libraries, header files form the viewable part of the library, whereas the rest is often pre-translated in translation units, i.e. not in the form of source text.

The integration of a header file into a translation unit by the translation program is initiated using special instructions. In C, for example, through the compiler instruction #include .

#include <stdio.h>

/* ... (weiterer Programmtext) */

In this case, the file is stdio.hincluded which contains declarations of functions that are important for reading and writing files and user input. It is part of the C standard library libc.


Header files work on the principle of textual replacement. In newer programming languages ​​such as Java or C # , this concept is no longer required. Instead, units are integrated that no longer offer text, but symbol information. This enables a better separation between interface and implementation and usually leads to shorter compilation times.


Program libraries whose full content (definitions, functions, etc.) is available in the form of one or more header files are referred to as header-only .

See also