I have searched and have been unable to verify how the GCC compiler will handle inlining getters and setters when declaration is in .h file and definition is in .cpp file.
Most seem to say that GCC can’t see across these source file barriers and won’t be able to inline these at all, while others disagree. I have looked at the documentation and I can’t find the answer there either. Did I miss it?
I do realize that inlining is a choice made by the compiler and is not always guaranteed, but assuming optimal situations, is it at least possible?
(What you really meant to ask is about the situation where the definition is in a different
.cppfile to the one you’re currently compiling, and then linked in later. The compiler doesn’t care about.hppor.cpp, but about translation units.)Anyway, on http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html, scroll down to “flno”:
So, yes, it’s possible to optimise inlines across module boundaries.
However, C++ still makes its requirement of:
So in fact you may not write your code to take advantage of this if you used the
inlinekeyword; you are instead reliant on the linker “just deciding” to inline your function if it sees fit. So it’s not an option that’s going to allow you to move your code around.Remember, writing
inlinein your code does not have a one-to-one relationship with a function actually getting physically inlined; it’s only a hint to the compiler (or linker, if you have the above mentioned link-time optimisations turned on).