What does 'inline' mean?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Jun 13 03:21:44 UTC 2020


On 6/12/20 8:52 PM, Manu wrote:
> On Fri, Jun 12, 2020 at 11:25 PM Andrei Alexandrescu via Digitalmars-d 
> <digitalmars-d at puremagic.com <mailto:digitalmars-d at puremagic.com>> wrote:
> 
>     On 6/8/20 2:14 AM, Manu wrote:
>      > In C/C++, inline says that a function will be emit to the binary
>     only
>      > when it is called, and the function is marked with internal
>     linkage (it
>      > is not visible to the linker from the symbol table)
> 
>     By my recollection this is not the case for C++, at all.
> 
>     * "inline" does NOT change a function's linkage in C++. You may have
>     inline functions with internal linkage (static inline) or (default)
>     external linkage. This is important because e.g. defining a static
>     variable in an extern inline function will have the same address in all
>     calls to the function.
> 
> 
> It absolutely changes the linkage.

No.

> I believe it uses what LLVM calls 'ChooseOne' in its code generator, I 
> don't know about 'standard' linker terminology, if such a thing exists.

It does: http://eel.is/c++draft/basic.link

> It's clearly in the spec too:
> """
> 
>  1. There may be more than one definition
>     <https://en.cppreference.com/w/cpp/language/definition#One_Definition_Rule> of
>     an inline function or variable in the program as long as each
>     definition *appears in a different translation unit* and (for
>     non-static inline functions and variables) all definitions are
>     identical. For example, an inline function or an inline variable may
>     be defined in a header file that is #include'd in multiple source files.
> 
> """

The quote does not even contain the word "linkage".

I'm insisting on this because it happens so often. We need to use the 
terms with the same meaning, otherwise we get bogged down in silly side 
quests "it doesn't change linkage" - "oh but it does" and there is no 
progress.


More information about the Digitalmars-d mailing list