There’s two things about inlining:
- The
inlinekeyword will be ignored if the compiler determines that the function cannot be inlined. - There is a compiler optimization (on Visual Studio, I don’t know about GCC) that tells the compiler to inline all functions where possible.
From this I conclude that I never need to bother about inlining. I just have to turn on the compiler optimization for the release build.
Or are there any situations where manually inlining would be preferred?
The
inlinekeyword has two functions:inline‘d symbol may be defined in multiple translation units (typically because it is defined in a header, that is included from multiple files). Normally, this would result in a linker error, but it is allowed when you use theinlinekeyword.