On the cppreference page for the inline
specifier, it says,
The
inline
specifier, when used in a function's decl-specifier-seq, declares the function to be an inline function.
An inline function has the following properties:
There may be more than one definition of an inline function in the program as long as each definition appears in a different translation unit and all definitions are identical.
...
Then, a bit down, it says,
The original intent of the
inline
keyword was to serve as an indicator to the optimizer that inline substitution of a function is preferred over function call. ...
Apart from this line, there is no reference to this use of inline
. Is the latter meaning of inline
still valid in the C++ standards? Or is the latter form deprecated over the former?
If the latter form is still valid, is it worth using it in modern compilers? I have heard that, even though it is the compiler that makes the decision about inlining, using the inline
keyword pushes it a bit. Is this true? Should I use the inline
keyword in my program for this case?
inline
is still valid and essential. The original intend is minor. – Raulinline
was never in the standard (I think?), "deprecated" isn't the right word. – Yueninline
is irrelevant. It was just a suggestion to the compiler. The compiler can do inlining with or without theinline
keyword. It only affects how the function is linked. – Redfieldinline
: github.com/search?l=C%2B%2B&q=inline&type=Code (compared toinclude
that has 328M, it is not too small) – Autochthonouslanguage-lawyer
. It's looking for a more practical answer (should I use inline to mean this...) – Aitkeninline
keyword or with other mechanisms) in every translation unit which calls the function, then the compiler (+linker) are guaranteed to produce an executable in which every reference to that function has the same address. As Pepijn said (correctly), the programmer must ensure that all the definitions are identical. That's it. The compiler will emit a "weak definition" in each TU, and the linker will choose one of those definitions. – Gutturalizeinline
function in multiple TUs. If that's what you meant to say, I did misunderstand. But I think it was not totally clear. – Gutturalize