The original purpose of inline functions was what you stated, but they're not used that way anymore.
The original idea was that a function tagged
would not actually be called when the compiler generated code. Instead, the compiler would copy its code in line
, executing it within whatever function was "invoking" the inline function. This would save the overhead of a function call and return, and possibly having to push arguments onto the stack, create a stack frame and destroy it, and whatever other code was generated for a function call. Any function could be tagged
; whether the compiler obeyed, by doing what I just described, was up to it. The trade-off was faster code at the cost of a larger executable, given that the function's code was cloned to each place were it was invoked. And if the inlined function had a bug, fixing it (assuming that the system had a patching capability) was painful because of all these clones.
These days, compilers are so good at optimizing code that they take it upon themselves to inline functions. In fact, they do it to the point where it's very difficult to debug an executable that has been aggressively optimized. So, functions are no longer tagged
for this purpose.
The meaning of
has therefore changed. Or, more accurately, only retains part of its original meaning. You can read a rather arcane explanation here
]. A good example of what it means is that I use
in a class template to tag a function that does not use the template parameter (e.g.
) and can therefore be shared by all instantiations of the template. If this makes no sense to you, don't worry. If you work with C++ long enough, it eventually will. :)