I understand inlining as the following:
A separate function which is marked as "inline" (assuming the compiler really does inline) will be "merged" into the function it is called.
i.e. (pseudo code)
void main ()
{
printf(b(2,3)) // will be printf(2*3*3);
}
inline function b(int x, int y)
{
return x*y*y;
}
However, I had a discussion regarding inlining and why am I advised to not inline functions that are called exactly once in my code(Because they are initialization functions)?
For example:
void main(){
initFunctionA();
SomeType destinationA;
SomeType destinationB;
InitDescriptionType description;
//initialize DescriptionType
initFunctionB(&description, destinationA&);
initFunctionC(&description, destinationB&);
}
inline void initFunctionA()
{
//do stuff
}
inline void initFunctionB(InitDescriptionType* desc, SomeType** destination)
{
// Take Description and put something into destination
}
inline void initFunction(InitDescriptionType* desc, SomeType** destination)
{
// Take Description and put something into destination
}
Wouldn't that mean that my output code is marginally smaller (since no jumps to functions etc?)
€dit: The linked question doesn't answer my particular question. In my Case, the Initialization is a single function. My thought was "Hey, why don't I separate my Initizalization into multiple smaller functions for readability and make them inline?"
inline
has almost no impact on whether the compiler will inline particular calls.