As we saw in the previous video, function calls have a
certain amount of overhead.
We need to create an activation record, push it on the stack,
deal with parameters, pop off the activation record when the function
terminates and deal with the return addresses and return values.
Although all of this can happen very quickly and
efficiently, it still happens.
Sometimes we have a very simple function and the function call
overhead might be greater than the time spent executing the function.
In cases such as these, we can suggest to the compiler
that it generate inline code.
Inline code is basically inline assembly code that avoids
the function call overhead.
Inline code is generally faster.
But if you inline a function many times, then you're duplicating
function code in many places and it could lead to larger binaries.
That said, compilers are so sophisticated now that
they'll likely inline code even without your suggestion.
Let's see what an inline function looks like.
Here you can see the syntax for an inline function.
We simply precede the function return type with the keyword inline.
Inline functions are usually declared in header or .h files since the
definition must be available to every source file that uses it.
As mentioned earlier, compilers are so good now that most will
make short functions like this inline anyway even if you don't
provide the inline keyword.
Don't worry too much about asking the compiler to inline your
functions, but now you know what inline functions are in case you
see them in c++ code out there.