K
Keith Thompson
Stephen Sprunk said:IIRC, GCC will automatically inline "small" functions, but "inline"
tells it to inline the function regardless of size. The size threshold
can be changed via command-line flag, but IMHO that's not as clean.
Also, I think GCC does not output a standalone function body if the
function is declared "static inline" but does if the function is merely
declared "static", even if every call to the latter gets inlined due to
heuristics.
So, "inline" is not (yet?) completely useless like "auto" or "register".
The "auto" keyword is completely useless (except perhaps as
documentation); it can only specify something that the compiler *must*
do in the absence of the keyword. It was useful in older versions of C,
where
auto x;
static y;
declared x and y as objects of type int (even there I'd prefer to
declare them as "int" explicitly, making the "auto" keyword
redundant).
The "register" keyword, on the other hand, is at least potentially
meaningful. The common wisdom is that the compiler can always do
a better job of register allocation than the programmer can, but
I'm not sure that's entirely true. It also has a semantic effect:
it forbids taking the address of the object. Even if the compiler
doesn't choose to store the object in a register, knowing that
its address is never computed might be helpful for optimization.
(Though since "register" can be applied only to objects with block
scope, a reasonably clever compiler should be able to determine
that for itself.)