HOME

TheInfoList



OR:

In the context of the C or
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
programming languages, a
library A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vir ...
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-oriente ...
s and
class Class 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 differentl ...
es comprising the library are visible to the
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
in a
header file Many programming languages and other computer files have a directive, often called include (sometimes copy or import), that causes the contents of the specified file to be inserted into the original file. These included files are called copybooks ...
form. Header-only libraries do not need to be separately
compiled In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
, 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 a ...
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 In computer programming, code bloat is the production of program code (source code or machine code) that is perceived as unnecessarily long, slow, or otherwise wasteful of resources. Code bloat can be caused by inadequacies in the programming lang ...
(arguably) – the necessary use of inline statements in non-class functions can lead to code bloat by over-inlining. Nonetheless, the header-only form is popular because it avoids the (often much more serious) problem of packaging. For
C++ templates C, or c, is the third letter in the Latin alphabet, used in the modern English alphabet, the alphabets of other western European languages and others worldwide. Its name in English is ''cee'' (pronounced ), plural ''cees''. History "C" ...
, 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 Only may refer to: Music Albums * ''Only'' (album), by Tommy Emmanuel, 2000 * ''The Only'', an EP by Dua Lipa, 2017 Songs * "Only" (Anthrax song), 1993 * "Only" (Nine Inch Nails song), 2005 * "Only" (Nicki Minaj song), 2014 * "The Only", by ...
C (programming language) libraries