It has a semantic effect. To simplify, a function marked inline
may be defined multiple times in one program — though all definitions must be equivalent to each other — so presence of inline
is required for correctness when including the function definition in headers (which is, in turn, makes the definition visible so the compiler can inline it without LTO).
Other than that, for inlining-the-optimization, "never" is a perfectly safe approximation. It probably has some effect in some compilers, but nothing worth losing sleep over, especially not without actual hard data. For example, in the following code, using Clang 3.0 or GCC 4.7, main
contains the same code whether work
is marked inline
or not. The only difference is whether work
remains as stand-alone function for other translation units to link to, or is removed.
void work(double *a, double *b) {
if (*b > *a) *a = *b;
}
void maxArray(double* x, double* y) {
for (int i = 0; i < 65536; i++) {
//if (y[i] > x[i]) x[i] = y[i];
work(x+i, y+i);
}
}
inline
withoutstatic
orextern
ever useful in C99?, and you might reviewextern inline
too. Note that it is worth making even non-inline functionsstatic
whenever possible; the compiler may well optimize them into inline code if it makes sense, but it can only do that if it knows the function will not be called from outside the current source file, which means the function must bestatic
. – Ulundstatic
functions, it just has to leave a copy for external callers around (increasing code size). Whether this affects inlining heuristics I do not know. There are other good reasons to make helper functionsstatic
though (less pollution of the global namespace, and hence the ability to use shorter, nicer names). – Ischia