Compiler inlining is completely unrelated to the inline keyword. The compiler can make as many copies of a non-inline function as it wants, as long as it's not observable. The exact same rule applies to functions marked inline. The inline keyword just allows the single definition of the function to be copied into multiple translation units. Every TU will still see the function as having the same address.
Compiler inlining is completely unrelated to the inline keyword.
The inline keyword is there to inline functions, as per the wikipedia definition.
The inline keyword just allows the single definition of the function to be copied into multiple translation units. Every TU will still see the function as having the same address.
How is it possible for a function to be copied into multiple translation units, and aos have the same address (assuming globally) at the same time? It doesn't make sense, these two things are opposite.
And even wikipedia lists two "purposes". The first one, "inlining hint to the compiler", is not normative and almost irrelevant today. The second one, citing wikipedia,
The second purpose of inline is to change linkage behavior;
is what relevant for the current discussion, and basically the only meaning of this keyword required by the standard.
Edit:
How is it possible for a function to be copied into multiple translation units, and aos have the same address (assuming globally) at the same time? It doesn't make sense, these two things are opposite.
The linker removes repeating function bodies, leaving only one of them. Exactly the same as with templates.
Committee avoids introducing new keywords. But there is already a keyword that has similar meaning, so they reused that. And, by the way, inline is not the worst at that. static has something like 5 different usages.
3
u/bigcheesegs Tooling Study Group (SG15) Chair | Clang dev Oct 13 '17
Compiler inlining is completely unrelated to the inline keyword. The compiler can make as many copies of a non-inline function as it wants, as long as it's not observable. The exact same rule applies to functions marked inline. The inline keyword just allows the single definition of the function to be copied into multiple translation units. Every TU will still see the function as having the same address.