What does 'inline' mean?

Manu turkeyman at gmail.com
Sat Jun 13 03:47:16 UTC 2020


On Sat, Jun 13, 2020 at 1:39 PM Manu <turkeyman at gmail.com> wrote:

> On Sat, Jun 13, 2020 at 1:30 PM Andrei Alexandrescu via Digitalmars-d <
> digitalmars-d at puremagic.com> wrote:
>
>> On 6/12/20 8:54 PM, Walter Bright wrote:
>> > On 6/12/2020 5:17 PM, Andrei Alexandrescu wrote:
>> >> Not sure about that part - if linkage was static by means of using the
>> >> "static" keyword, multiple definitions may not be merged. (I may be
>> >> wrong, please correct me.) Consider:
>> >>
>> >> static inline int fun() {
>> >>      static int x;
>> >>      return ++x;
>> >> }
>> >>
>> >> In C++, each translation unit containing a definition of fun() will
>> >> have a distinct address for x. I don't see how the bodies of those
>> >> functions can be merged.
>> >
>> > They are not merged in D, for the simple reason that ModuleA.fun() and
>> > ModuleB.fun() will have different (mangled) names presented to the
>> linker.
>>
>> For D the question is if they are merged if the function is defined in a
>> .di file and imported in two other modules.
>>
>
> They are not 'merged', they just don't exist.
> The problem I've repeated many times for D is that it doesn't emit the
> function ANYWHERE, and as such, you get a "undefined symbol" error. This is
> different than C++ where you would have gotten a "multiply defined symbol"
> error, but it's exactly the same problem for the exact same reason. It just
> manifests differently because C++ has .h files which naturally duplicates
> the code into each CU and D doesn't.
>

And where I say "it's the same problem", perhaps it's better to say "it's
the same issue"; about the requirement to emit inline code to each
referencing CU, and what the linkonce link flags are designed to address.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20200613/482d6d62/attachment.htm>


More information about the Digitalmars-d mailing list