Title: Inline function(C++) is efficient, why don't we define every function as inline function?
Tags: c++
Question: In line function is quite efficient, so I was confused why don't we define every function as inline funciton?

Comment: In modern compilers, inline has nothing to do with efficiency.

Comment: Take a look at http://stackoverflow.com/questions/1932311/ or maybe http://stackoverflow.com/questions/3999806

Comment: Inlining 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.

Here is the accepted answer: 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.


Here is another answer: 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.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:02/11/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c++>', 'Title': "Inline function(C++) is efficient, why don't we define every function as inline function?", 'ViewCount': 1228, 'id': 35344214, 'user_AboutMe': '', 'user_AccountId': 7180272.0, 'user_DisplayName': 'Hanslen Chen', 'user_Reputation': 440.0, 'user_Views': 46.0, 'user_id': 5484516.0}}