What does 'inline' mean?
evilrat
evilrat666 at gmail.com
Mon Jun 8 08:42:14 UTC 2020
On Monday, 8 June 2020 at 06:14:44 UTC, Manu wrote:
>
> I think a first part of the conversation to understand, is that
> since D doesn't really have first-class `inline` (just a
> pragma, assumed to be low-level compiler control), I think most
> people bring their conceptual definition over from C/C++, and
> that definition is a little odd (although it is immensely
> useful), but it's not like what D does.
>
> 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 this definition; what inline REALLY means is that the
> function is not
> placed in the binary where it is defined, it is placed in the
> binary where
> it is CALLED, and each CU that calls an inline function
> receives their own
> copy of the function. From here; optimisers will typically
> inline the call
> if they determine it's an advantage to do so.
>
Sorry for sticking in my nose, but in result inline in C++ simply
tells the linker "this symbol could be present multiple times,
just pick whichever one of them and done with it" so it won't
complain about multiple symbols anymore.
And that's why you have to slap inline to functions that have
body in header in order to build.
But I'm not very certain if that's all about it, not using C++
that much since then, and never to that truly deep extent where
any loose bit can destroy performance, not beyond fixing the
client's code and some crappy pet projects.
More information about the Digitalmars-d
mailing list