My understanding of inline keyword is that it is a request for the compiler to inline the contents of a function (like a copy and past). And that the compiler might ignore the inline request for optimization reasons. And the FORCELINE keyword is meant to force an inline function, but is really more of a stronger request?
I most often use it for simple Getters and Setters in the header file.
But am checking if it is good practice to use inline/forceinline for trivial function extractions, such as long and verbose if statements that return true/false:
if (InlinedFunction()) {}
What about multi-line function extractions?
I am only extracting functions for better readability and don’t want the overhead of extra additional function calls.
Also, if the function declaration and implementation are separated into a header and .cpp file, should I specify the forceinline keyword at both the declaration and implementation?
I expect my extracted functions to simply be copy/pasted, such that the function they are pasted in is the same but neater for human readability. But I do not know if I am setting myself up for problems later, since many search results on the topic recommend I simply not use inline/forceinline.
Waffle Dragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4