HOME

TheInfoList



OR:

In the context of the C or C++ programming languages, a
library A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
is called header-only if the full definitions of all macros,
function Function or functionality may refer to: Computing * Function key, a type of key on computer keyboards * Function model, a structured representation of processes in a system * Function object or functor or functionoid, a concept of object-orie ...
s and
class Class, Classes, or The Class may refer to: Common uses not otherwise categorized * Class (biology), a taxonomic rank * Class (knowledge representation), a collection of individuals or objects * Class (philosophy), an analytical concept used d ...
es comprising the library are visible to the
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
in a
header file An include directive instructs a text file processor to replace the directive text with the content of a specified file. The act of including may be logical in nature. The processor may simply process the include file content at the location of ...
form. Header-only libraries do not need to be separately compiled, packaged and installed in order to be used. All that is required is to point the compiler at the location of the headers, and then the header files into the application source. Another advantage is that the compiler's optimizer can do a much better job when all the library's source code is available. The disadvantages include: * brittleness – most changes to the library will require recompilation of all
compilation unit In C and C++ programming language terminology, a translation unit (or more casually a compilation unit) is the ultimate input to a C or C++ compiler from which an object file is generated. A translation unit roughly consists of a source file af ...
s using that library, * longer compilation times – the compilation unit must see the implementation of all components in the included files, rather than just their interfaces, * machine- code bloat (arguably) – the necessary use of inline statements in non-class functions can lead to code bloat by over-inlining, * harder to understand as the header contains both the interface and the implementation whereas traditional library separate both. Nonetheless, the header-only form is popular because it avoids the (often much more serious) problem of packaging. For C++ templates, including the definitions in header is the only way to compile, since the compiler needs to know the full definition of the templates in order to instantiate.


References

{{reflist C++ Only C (programming language) libraries