There are two implications of using the inline
keyword(§ 7.1.3/4):
- It hints the compiler that substitution of function body at the point of call is preferable over the usual function call mechanism.
- Even if the inline substitution is omitted, the other rules(especially w.r.t One Definition Rule) for inline are followed.
Usually any mainstream compiler will substitute function body at the point of call if needed, so marking function inline
merely for #1
is not really needed.
Further w.r.t #2
, As I understand when you declare a function as static inline
function,
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)
Thus such a function acts like any other static
function and the keyword inline
has no importance anymore, it becomes redundant.
So, Practically marking a function static
and inline
both has no use at all. Either it should be static
(not most preferred) or inline
(most preferred),
So, Is using static
and inline
together on a function practically useless?