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:



Table Of Contents