betterC shared static ctor
Mike Parker
aldacron at gmail.com
Wed Jul 21 08:28:22 UTC 2021
On Wednesday, 21 July 2021 at 08:11:06 UTC, vit wrote:
> Is it possible to call all shared static ctors in betterC?
>
> ```d
> //-betterC
>
> static immutable int i;
>
> shared static this(){
> i = 42;
> }
> extern(C) void main(){
> assert(i != 42);
>
> }
> ```
These rely on DRuntime, which is not linked in betterC mode.
You'll need to use the `crt_constructor` and `crt_destructor`
pragmas:
https://dlang.org/spec/pragma.html#crtctor
Apply them to any `extern(C) function for static ctor/dtor
behavior.
More information about the Digitalmars-d-learn
mailing list