Foreword:
Embedding a function, that is, an act of nesting, that is, a built-in extension, is an optimization where a function call is replaced by a duplicate set of instructions.
To declare an inline function, you must declare to the linker that the function must be handled differently than non-inline functions. In particular, one definition rule is different from built-in functions. Internal functions are allowed to be defined in several translation units (and in fact they must be defined in all translation units where the function is used by odr). This differs from non-line functions, which must be defined in only one translation unit. The inline can be used to declare an inline function.
While an inline ad is called similarly to inlining optimizations, while the former can indirectly influence whether the latter is possible, the two concepts are separate.
Now to answer.
If I want the function to be inlined, I have to use the inline in the declaration.
You do not have to use the inline keyword. A non-inline function call can be extended by the built-in compiler if the function is defined in the same translation unit. Even this is not a requirement for a link optimizer that sees all translation units.
Example:
// a.cpp void foo(){} // a non-inline function inline void qux(){} // an inline function void bar(){ foo(); // this call to a non-inline function can be expanded inline // because the function is defined in the same TU } // b.cpp void foo(); // the non-inline function must not be defined // in multiple translation units inline void qux(){} // the inline function can and must be defined // in both translation units void xeb(){ foo(); // this call to a non-inline function can not be expanded inline by // the compiler because the function is not defined in the same TU // the call can be expanded by a linker qux(); // this call can be expanded by the compiler // because the function is defined in the same TU }
However, link optimization is not always an option, and function calls are made through translation units, so a built-in definition in some cases is really necessary to enable built-in extension.
Pedantic point: a function can be declared inside a string without the inline (if it is a member function).
Why can't I use inline when calling a function?
There is simply no such syntax in the language.
Note that a function must still be defined in the same translation unit, otherwise it cannot be extended by the built-in compiler. Thus, a function must still be declared inline if you want an inline extension in more than one translation unit.
I suspect the reason for the lack of syntax for forced expansion inside is probably the same as why there is no way to choose which branch of the if is the default branch, which may have a slight effect on performance (reasoning is just my guess in both cases ): People are known to be poorly optimized. I see no technical reason why such a language function cannot be introduced. But I would not expect such a feature to be very useful.