[Issue 17868] add pragma(crt_con/destructor[, priority])

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 4 19:42:54 UTC 2017


https://issues.dlang.org/show_bug.cgi?id=17868

--- Comment #6 from Martin Nowak <code at dawg.eu> ---
(In reply to Rainer Schuetze from comment #4)
> This enables "system programming" by not adding every special case to the
> compiler as it is done so far.

It's a common enough use case to warrant a separate pragma.
Also just adding pointers to a section is not enough, the section needs to be
flagged accordingly for this to work (e.g. on OSX and ELF).
See WIP https://github.com/MartinNowak/dmd/tree/fix17868.

> Where custom args would vary based on what the compiler supports. This way, the ctr_constructor part is standardized, but the custom args obviously depend on support from the specific compiler. Use version statements as needed.

Version statements for pragmas are a pain, you need to add a forwarding
function or repeat the implementations.

version (DMD)
   pragma(constructor, 1234)
   void func() { /* repeat */ }
else
   pragma(constructor)
   void func() { /* repeat */ }

Pragma arguments don't expand AliasSeq tuples, so that cannot be used either.

Also priority support is platform/linker dependent, not compiler dependent.
IMO simply making it only do sth. on supported platforms is an easy solution to
this.

I'd rather drop support for priorities instead of complicating the usage,
leaving priorities to GDC/LDC's non-standard intrinsics. We're not that likely 
to ever need it, but then again it would be cheap to just implement it right
away, and someone coming from C/C++ might want to use it.

--


More information about the Digitalmars-d-bugs mailing list