Creating weak symbols with D
Sat Aug 8 18:56:33 UTC 2020
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:
>> 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
> https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/attributes.d), 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.
Another important advantage is that they can be easily
introspected and enabled conditionally as they're just tuples. I
think that the design of UDAs in D is one of the underrated
language design success stories :)
More information about the Digitalmars-d