What does 'inline' mean?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Jun 13 03:25:35 UTC 2020
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.
More information about the Digitalmars-d
mailing list