Inline functions


#1

What does inlining a function actually do? How does a compiler interpret the inline request?


#2

Inline functions are used when the function has only one line of code. It avoids linking time by copying the code inside the function at the function call. To make a function inline keyword is used.


#3

An inline function is one qualified with the keyword inline. 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).
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.


#4

a function can be made inline by using inline keyword. by writing inline keyword, the function doesnt become inline.
inlining is just a request to compiler. compiler can refuse inline linkage. compiler will ignore if that function contains any loop, static variable, switch statement.


#5

basically inline keyword is used in functions.if function is called during execution of a program then there is stack maintantained for that function.
if the function is declared as inline then during execution there is no need to maintain a stack and no need of linkage.
inline functions works for only small bit of code.beacuse for large code must maintain the stack.so even a small function which is not declared as inline ,internally compiler treate it as inline function.