Under What condition an inline function ceases to be an inline function and acts as any other function?
The Myth:inline
is just a suggestion which a compiler may or may not abide to. A good compiler will anyways do what needs to be done.
The Truth:inline
usually indicates to the implementation that inline substitution of the function body at the point of call is to be preferred to the usual function call mechanism. An implementation is not required to perform this inline substitution at the point of call; however, even if this inline
substitution is omitted, the other rules(especially w.r.t One Definition Rule) for inline
are followed.
Under What condition an
inline
function ceases to be aninline
function and acts as any other function?
Given the quoted fact there is a deeper context to this question.
When you declare a function as static inline
function, the function acts like any other static
function and the keyword inline
has no importance anymore, it becomes redundant.
The static
keyword on the function forces the inline
function to have an internal linkage.(inline
functions have external linkage)
Each instance of such a function is treated as a separate function(address of each function is different) and each instance of these functions have their own copies of static local variables & string literals(an inline
function has only one copy of these ).
It's at the discretion of the compiler.
But some cases just can't be inlined, like:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With