S
santosh
Willem said:santosh wrote:
) Ioannis Vranos wrote:
)> In any case, how much size will you save if you make this
one-called )> function inlined? The same minus a function call (an
address) in the )> automatic storage.
)
) The main purpose of inline is to take away the function call and
return ) overhead, and this can make sense only for a function that is
very ) small and finishes very quickly, and is called often, or if the
) performance of that function is critical. Otherwise the code for the
) function is going to swamp any benefit from shaving of the
call/return ) instructions. Using inline for affecting code size is,
IMO, misusing ) it. Again the standard inline keyword is like
register: just a hint. A ) macro is going to give you an assurance of
inlining at the cost of loss ) of parameter type checking, or you
might try compiler specific options ) to force inlining of certain
functions.
A secondary, but very important, reason for inlining large functions
is to give the optimizer more things to work with, and therefore a
better chance
to optimize the code. Take this example:
/* some code */
verylargefunction(25, 3, &args);
/* some more code */
verylargefunction(35, 2, &moreargs);
/* and some other code */
verylargefunction(10, 0, NULL);
/* and a bit more code */
Now, verylargefunction() is a very large function that does a lot of
work. It is called three times, with constants as parameters.
By inlining the function, the compiler can suddenly do lots and lots
of constant expression evaluation inside verylargefunction().
Note also the NULL parameter at the third call. Suppose that inside
verylargefunction(), that parameter is used often to store results,
except when it's NULL. That is, each access has code similar to:
if (param3) param3[x]=y;
If this function is inlined, all those if-statements are optimized
away, and for the third call, the accesses are optimized away as well.
This is a huge reason for marking large functions inline.
Okay, I see your point, but wouldn't declaring the function static
(assuming that it can be of course) have the same effect minus
duplication?