Creating weak symbols with D

Johan j at
Sun Aug 9 09:55:51 UTC 2020

On Sunday, 9 August 2020 at 02:30:22 UTC, sarn wrote:
> On Saturday, 8 August 2020 at 18:43:31 UTC, Johan wrote:
>> On Saturday, 8 August 2020 at 18:14:34 UTC, Stefan Koch wrote:
>>> On Saturday, 8 August 2020 at 17:59:08 UTC, Andrei 
>>> Alexandrescu wrote:
>>>> C and C++ define __attribute__((weak)) to introduce weak 
>>>> symbols. It would be great if D could have a corresponding 
>>>> @weak attribute.
>>> pragma(weak) sounds better to me.
>>> pragmas are suppose to change codgen, and the usecase is 
>>> seldom enough that you wouldn't want to take name for it.
>> This argumentation doesn't make sense to me. Not all pragmas 
>> change codegen, and there are many things that change codegen 
>> that are not pragmas.
> Maybe the ship has already sailed, but existing linker-related 
> tweaks in standard D are done with pragmas (or extern).  E.g., 
> pragma(mangle) and pragma(crt_constructor).

DMD simply doesn't have a lot of linker-related functionality 
(no: weak, section, alias). GDC and LDC both do these things with 
magic UDAs, because UDAs fit much better in the language. 
(introspection, combining into AliasSeq, things like, etc.)

(Btw, pragma(mangle) and `extern` are not _linker_ related. )


More information about the Digitalmars-d mailing list