Which inline-s are useless, presuming, that all functions
actually must be inlined? Where is an inline missing?
(put in a header file, these all worked for me)
// function case
inlineint iDecDefC() {return 1;}
inlineint iDecDef();
inlineint iDecDef() {return 10;}
inlineint iDec();
inlineint iDec() {return 100;}
int iDef();
inlineint iDef() {return 1000;}
// method case
struct X
{
inlineint iDecDefC() {return 1;} // inline anyway
inlineint iDecDef();
inlineint iDec();
int iDef();
};
inlineint X::iDecDef() {return 10;}
inlineint X::iDec() {return 100;}
inlineint X::iDef() {return 1000;}
However, I don't know if that will be an inline function/method, if "inline" appears just in the declaration, I guess, no, maybe just in case of a method? (however, that's not very important)
One more idea: can it be, that when a LONG inline function is used into multiple translation units, compiler decides not to inline it and subsequently that function (previously #included everywhere) becomes defined in multiple places for linker?
"inline" is a request to the compiler to write the function body at the point of invocation. But if the function contains any loop, or the method is virtual or the body of the function body is large then compiler ignores the "inline" request and creates the function body with static linkage. So, if such a function is referred in multiple translational units then each unit gets its own copy of the method.
The concept of virtual functions and inline functions conflicts each other. Decision to make a method inline is taken at compile time whereas the virtual methods are invoked at run time. So compiler just ignores the inline request if the method is virtual.
But if the function contains any loop, or the method is virtual or the body of the function body is large then compiler ignores the "inline" request and creates the function body with static linkage.
This is not true. It's still up to the compiler whether or not it will be inlined.
Obviously if a function is called polymorphically it can't be inlined, but that doesn't mean that virtual functions can never be inlined.
For example:
1 2 3
B b;
b.func(); // not called polymophically, can still be inlined
// even if func is virtual
EDIT:
And I also don't see what having a loop has to do with anything.
I think, there are no specific rules put forward by C++ standard when to skip inlining. Its upto the compiler designers whether to inline or skip inlining of a function. However compiler designers still follows some rules as I mentioned.
One more scenario where inline is skipped:
When you have an inline method, but you use its function pointer.
Disch,
What I meant is, inlining is skipped when you have a virtual method and somewhere in code you invoke it polymorphically. In this scenario, compiler won't do inlining of that method even if you invoke without polymorphism.