What does 'inline' mean?

Walter Bright newshound2 at digitalmars.com
Sat Jun 13 04:05:14 UTC 2020


On 6/12/2020 8:25 PM, Andrei Alexandrescu 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.

If the di file is mentioned on the command line to the compiler, yes (1) 
instance of it appears in the executable. Otherwise, (0) instances of it appear 
in the executable. There are never 2 or more instances in the executable.


More information about the Digitalmars-d mailing list