Encyclopedia > Header file

  Article Content

Header file

In computer programming, a header file is a text file containing small bits of program code, which is used to describe the contents of the main body of code to other modules.

Programs are typically broken into pieces in order to make working with them easier. Related bits of code are collected into files, which can then be referred to from other files. However this leads to a problem when the code is collected into a runnable program, because all of the code must be compiled every time.

One solution to this problem is to have the system examine the modification dates of the files that make up the program. However this might tell the system to compile files that have had rather innocuous changes made to them, like fixing whitespace, or adding comments.

The header file provides a solution to this problem by separating out the parts that really have an effect when changed, from those that do not. Typically, header files are used to specify only interfaces, with the implementations left in the main code files.

In this case, they consist of "stub" definitions containing only the definition for the interfaces implemented in the main file, along with documentation for that code. This way the header file only changes if and when the very definition of the code changes, which is the time when other modules must also be recompiled as well. Now the system only has to look at the modification dates on the header files to see what needs to be re-built, which can result in significant savings.

On the downside a header file means two files to modify when a change is made. Newer languages (like Java) typically dispense with header files and instead put a little more smarts into the system to see if the changes really have any effect.

See also:



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
UU

... page; that is, one that just points to other pages that might otherwise have the same name. If you followed a link here, you might want to go back and fix that ...

 
 
 
This page was created in 26.3 ms