C++ Inline Functions

Inline functions are used in C++ to reduce the overhead of a normal function call. A function is declared inline by using the specifier inline for C++ functions or _Inline for C functions. The inline specifier is a suggestion to the compiler that an inline expansion can be performed. Instead of transferring control to and from the function code segment, a modified copy of the function body may be substituted directly for the function call.

An inline function can be declared and defined simultaneously. If it is declared with the keyword inline or _Inline, it can be declared without a definition. The following code fragment shows an inline function definition. Note that the definition includes both the declaration and body of the inline function.

inline int add(int i, int j) { return i + j; }

Both member and nonmember functions can be inline, and both have internal linkage.

The use of the inline specifier does not change the meaning of the function. The inline expansion of a function may not preserve the order of evaluation of the actual arguments.



Inline Member Functions
Inline Specifiers