Reputation: 3241
Suppose we fave a following header file:
Header1.h
#include "Header2.h"
class A
{
public:
void Function();
}
inline void A::Function()
{
// Code ...
OtherFunction(); // Function from Header2.h
// Code ...
}
If a compiler actually chooses to inline the Function
what would happen with the call to OtherFunction
:
OtherFunction
definition was available for current translation unit, could it also possibly be inlined within the body of Function
? (Basically are nested inlines available?)OtherFunction
definition was not available for current translation unit, will it remain a simple function call, while the code around it gets inlined? (In a situation where compiler chose to inline Function
)Upvotes: 0
Views: 88
Reputation: 6824
Most of the modern compilers actually inlines functions for you when you build your application in release configuration - The effect of OtherFunction
being declared as inlined/normal will be the same as compiler will decide which is the better option. I certainly know this hapens with MSVC10 and above compilers (Visual Studio). As a matter of fact, inline whatever you want but the compiler ultimately governs what gets inlined.
An example is that if your function calls are chained in a way that the push and pop operations won't make sense after inline
your functions won't be inlined (even if you declare them to be inline
d)
If it makes things any easier - see:
When to use inline function and when not to use it?
Benefits of inline functions in C++?
More importantly, How deep do compilers inline functions?
has already got a good explanation.
Upvotes: 1