Creating weak symbols with D

Johan j at
Sat Aug 8 18:43:31 UTC 2020

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:
>> Weak symbols ( are 
>> not often needed, but they are, they're needed badly.
>> 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.
LDC has the @ldc.attributes.weak magic UDA (in, and I'm sure GDC has something very similar. (LDC also has the (very old) pragma(LDC_extern_weak), which should be changed to a magic UDA.)
LDC chose to implement these things as UDAs because it offers a 
few benefits over pragmas, one of which is that it doesn't need 
compiler surgery.


More information about the Digitalmars-d mailing list