for the following function:
inline void A() {
...
B();
...
}
is B also inlined by the compiler?
If not, should I make B inline to increase performance?
In most situations, you can rest comfortably leaving inlining-decisions to the compiler, which will know far better than you when and when not it will result in better performance.
In this specific situation, I would stronlgy suspect that it is completely up to the compiler what to do.
inline is not a hint at all..No, the inline keywords will only cause the A code to be inlined inside the caller code. This will not affect inlining of B.
Besides this, in c++, the inline keyword is only a hint to the compiler, which is allowed to ignore it. Modern compilers decide when the functions need to be inlined, even if the keyword is not used.
Somehow all the commenters failed to mention that there are cases when inline is NOT a mere hint to the compiler, but a mandated keyword. It happens when one puts a non-template definition of a function in the header file included by multiple .cpp files. In this case absence of inline will trigger a linker error. As a matter of fact, this is the only case when one should even bother typing those 6 characters. In other cases, compilers will inline everything they can - regardless of this keyword presence.
inline just resolve the linker error?When you declare a function/method inline, it is just a hint to the compiler that this particular function should be inlined. The compiler then may or may not inline it. The same applies for nested calls like the call to B() inside A().
I would probably add inline specifier to both of the functions, but that's just a matter of style - modern optimizing compiler like GCC will optimize it anyways.