What is function inlining

suggest change
inline int add(int x, int y)
{
    return x + y;
}

int main()
{
    int a = 1, b = 2;
    int c = add(a, b);
}

In the above code, when add is inlined, the resulting code would become something like this

int main()
{
    int a = 1, b = 2;
    int c = a + b;
}

The inline function is nowhere to be seen, its body gets inlined into the caller’s body. Had add not been inlined, a function would be called. The overhead of calling a function – such as creating a new stack frame, copying arguments, making local variables, jump (losing locality of reference and there by cache misses), etc. – has to be incurred.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Inline functions:
* What is function inlining

Table Of Contents
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
111 Inline functions
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype