There is such thing and it's in the latest C++ draft:
At § 7.1.2 .4:
An inline function shall be defined in every translation unit in which it is odr-used and shall have exactly the same definition in every case (3.2). [ Note: A call to the inline function may be encountered before its definition appears in the translation unit. — end note ] If the definition of a function appears in a translation unit before its first declaration as inline, the program is ill-formed. If a function with external linkage is declared inline in one translation unit, it shall be declared inline in all translation units in which it appears; no diagnostic is required. An inline function with external linkage shall have the same address in all translation units. A static local variable in an extern inline function always refers to the same object. A type defined within the body of an extern inline function is the same type in every translation unit.
Some insights on what is this and when to use it?
The extern-inline module supports the use of C99-style extern inline functions so that the code still runs on compilers that do not support this feature correctly. C code ordinarily should not use inline .
Inline function in C++ is an enhancement feature that improves the execution time and speed of the program. The main advantage of inline functions is that you can use them with C++ classes as well.
Similarly, if you define a function as extern inline , or redeclare an inline function as extern , the function simply becomes a regular, external function and is not inlined. End of C only. Beginning of C++ only.
Advantages :- 1) It does not require function calling overhead. 2) It also save overhead of variables push/pop on the stack, while function calling. 3) It also save overhead of return call from a function. 4) It increases locality of reference by utilizing instruction cache.
extern
is redundant for functions, so it is pointless to declare a function extern inline
. If, for example you declared a function inline
at global scope, the rules of this section would apply. Likewise if you declared a class at global scope and defined a member function within the class definition, as such a function would be implicitly inline
.
The question of when you should declare a function inline
is a can of worms I'm not inclined to open here. See: When should I write the keyword 'inline' for a function/method?
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