Inline function
Function in the C and C++ programming languages / From Wikipedia, the free encyclopedia
Dear Wikiwand AI, let's keep it short by simply answering these key questions:
Can you list the top facts and stats about Inline function?
Summarize this article for a 10 year old
SHOW ALL QUESTIONS
This article is about inline functions in C and C++. For inline expansion more generally, see Inline expansion.
Not to be confused with Inline assembler.
In the C and C++ programming languages, an inline function is one qualified with the keyword inline
; this serves two purposes:
- It serves as a compiler directive that suggests (but does not require) that the compiler substitute the body of the function inline by performing inline expansion, i.e. by inserting the function code at the address of each function call, thereby saving the overhead of a function call. In this respect it is analogous to the
register
storage class specifier, which similarly provides an optimization hint.[1] - The second purpose of
inline
is to change linkage behavior; the details of this are complicated. This is necessary due to the C/C++ separate compilation + linkage model, specifically because the definition (body) of the function must be duplicated in all translation units where it is used, to allow inlining during compiling, which, if the function has external linkage, causes a collision during linking (it violates uniqueness of external symbols). C and C++ (and dialects such as GNU C and Visual C++) resolve this in different ways.[1]
This article needs to be updated. The reason given is: Meaning of inline changed in C++ (https://en.cppreference.com/w/cpp/language/inline). (April 2019) |