In line function is quite efficient, so I was confused why don't we define every function as inline funciton?
Asked
Active
Viewed 1,436 times
0
-
3Inlining functions doesn't always inject their code into the call site, and it's not all sunshine and roses, anyway. See [this question](http://stackoverflow.com/questions/145838/benefits-of-inline-functions-in-c), specifically the [second answer](http://stackoverflow.com/a/145952/4892076). Declaring a function `inline` is more about linkage than code generation these days, as well. – jaggedSpire Feb 11 '16 at 16:08
-
Take a look at http://stackoverflow.com/questions/1932311/ or maybe http://stackoverflow.com/questions/3999806 – Moby Disk Feb 11 '16 at 16:08
-
In modern compilers, inline has nothing to do with efficiency. – SergeyA Feb 11 '16 at 16:11
2 Answers
1
Marking every function inline will not make your functions inline its totally dependent on compiler! sometimes it may inline sometimes it may not. Also inling will not get you any befinites if it involves a loop.

Neeraj Jha
- 123
- 1
- 8
0
Apart from the call overhead I would mention that pasting the code allows the compiler to make further optimization at call site.
There are few cases in which is impossible to inline:
- Procedures linked from shared objects
- callback function that are invoked using function pointers
- recursive function (non tail recursive) i.e. (function call don't need to hang waiting for the recursive call to return)(can be easily and automatically converted to an iterative form)
Inlining also affects dimension of the executable that end up in more disk usage and longer load time.

Davide Spataro
- 7,319
- 1
- 24
- 36