static this not run?
Nicholas Wilson
iamthewilsonator at hotmail.com
Sat Sep 30 12:07:21 UTC 2017
On Saturday, 30 September 2017 at 08:49:14 UTC, user1234 wrote:
> On Saturday, 30 September 2017 at 06:15:41 UTC, Nicholas Wilson
> wrote:
>> No "initialising onError", the static this is not even being
>> run!
>> I'm using LDC master.
>>
>> See also https://github.com/libmir/dcompute/issues/32
>
> LDC 1.4, DMD 2.076, DMD ~master and finally GDC all give the
> expected result here
>
> "initialising onErrorinitialising onError: funcptr = 0x<some
> address>"
>
> each time using:
>
> ---
> enum Status {success,}
>
> class StatusException : Exception
> {
> this(Status s) {this.s = s;super("");}
> Status s;
> }
>
> void delegate(Status) onError;
>
> static this()
> {
> import core.stdc.stdio;
> printf("initialising onError");
> onError = (Status s) { throw new StatusException(s);};
> printf("initialising onError: funcptr = 0x%x",
> onError.funcptr);
> }
>
> void main()
> {
> import std.stdio;
> writeln(onError.funcptr);
> }
> ---
Hmm. Everything except for the main function was in a different
module, I dont see why that would cause it to not be run, but
then bugs have a tendency to do strange things like that. I'll
have to dust mite DCompute and see what it gets as a minimal case.
More information about the Digitalmars-d-learn
mailing list