<div dir="ltr"><div dir="ltr">On Sat, Jun 13, 2020 at 1:25 PM Andrei Alexandrescu via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 6/12/20 8:52 PM, Manu wrote:<br>
> On Fri, Jun 12, 2020 at 11:25 PM Andrei Alexandrescu via Digitalmars-d <br>
> <<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a> <mailto:<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>>> wrote:<br>
> <br>
>     On 6/8/20 2:14 AM, Manu wrote:<br>
>      > In C/C++, inline says that a function will be emit to the binary<br>
>     only<br>
>      > when it is called, and the function is marked with internal<br>
>     linkage (it<br>
>      > is not visible to the linker from the symbol table)<br>
> <br>
>     By my recollection this is not the case for C++, at all.<br>
> <br>
>     * "inline" does NOT change a function's linkage in C++. You may have<br>
>     inline functions with internal linkage (static inline) or (default)<br>
>     external linkage. This is important because e.g. defining a static<br>
>     variable in an extern inline function will have the same address in all<br>
>     calls to the function.<br>
> <br>
> <br>
> It absolutely changes the linkage.<br>
<br>
No.<br></blockquote><div><br></div><div>Dump a binary with and without `inline`; look at the link flags... they are different.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> I believe it uses what LLVM calls 'ChooseOne' in its code generator, I <br>
> don't know about 'standard' linker terminology, if such a thing exists.<br>
<br>
It does: <a href="http://eel.is/c++draft/basic.link" rel="noreferrer" target="_blank">http://eel.is/c++draft/basic.link</a><br>
<br>
> It's clearly in the spec too:<br>
> """<br>
> <br>
>  1. There may be more than one definition<br>
>     <<a href="https://en.cppreference.com/w/cpp/language/definition#One_Definition_Rule" rel="noreferrer" target="_blank">https://en.cppreference.com/w/cpp/language/definition#One_Definition_Rule</a>> of<br>
>     an inline function or variable in the program as long as each<br>
>     definition *appears in a different translation unit* and (for<br>
>     non-static inline functions and variables) all definitions are<br>
>     identical. For example, an inline function or an inline variable may<br>
>     be defined in a header file that is #include'd in multiple source files.<br>
> <br>
> """<br>
<br>
The quote does not even contain the word "linkage".<br>
<br>
I'm insisting on this because it happens so often. We need to use the <br>
terms with the same meaning, otherwise we get bogged down in silly side <br>
quests "it doesn't change linkage" - "oh but it does" and there is no <br>
progress.<br></blockquote><div><br></div><div>That's because this is a C++ spec, and C++ is not a linker. The spec just specifies the required semantics, and the compiler implements them.</div><div>The compiler happens to implement them appropriately for the linking ecosystem (by using appropriate link flags), because that's how native code works... you build modules and then link them with a linker which is outside the domain of the language spec.</div><div><br></div><div>The whole point is that different languages can interact with each other successfully in 'linker space'. Unless we want to have a self-contained language island, we can't ignore that a linker will link our code (together with other code), and the compilers output has to work properly in that environment.</div><div>Like C++, we don't need to spec details about link flags, but the compiler implementation still needs to implement them in those terms, cus that's how the ecosystem has been designed to work.</div><div><br></div><div>I imagine any changes made here would have a similar expression in the D spec as what you read in the C++ spec... and the practical reality is the implementation will apply the appropriate link flags to the symbols.</div></div></div>