|If inlining is just inserting the function into the calling function|
|A function declared with an inline function specifier is an inline function. The|
function specifier may appear more than once; the behavior is the same as if it appeared
only once. Making a function an inline function suggests that calls to the function be as
fast as possible.118) The extent to which such suggestions are effective is
118) By using, for example, an alternative to the usual function call mechanism, such as ‘‘inline
substitution’’. Inline substitution is not textual substitution, nor does it create a new function.
Therefore, for example, the expansion of a macro used within the body of the function uses the
definition it had at the point the function body appears, and not where the function is called; and
identifiers refer to the declarations in scope where the body occurs. Likewise, the function has a
single address, regardless of the number of inline definitions that occur in addition to the external
|But then foo()'s x is in the scope of main()'s x, right?|
|Not sure what you mean - the inner assignment refers to the inner x and the outer assignment refers to the outer x, so this works for this simple example.|
inlineis implementation defined when creating this thread. I assumed it was a straight substitution with some black magic dealing with return value.
inlinewhen making decisions about inlining. The keyword specifies that multiple definitions are allowed and that function local statics , string literals, and closures are shared among all definitions, which involves black magic at linker level. Inlining is just normal optimization, like dead code elimination.