digitalmars.D.learn - static this not run?
- Nicholas Wilson (46/46) Sep 29 2017 I want a module level initialised delegate. if I try
- user1234 (29/33) Sep 30 2017 LDC 1.4, DMD 2.076, DMD ~master and finally GDC all give the
- Nicholas Wilson (5/39) Sep 30 2017 Hmm. Everything except for the main function was in a different
- kinke (3/8) Sep 30 2017 [The object needs to be pulled in during linking.]
I want a module level initialised delegate. if I try module foo; enum Status { success, } class StatusException : Exception { Status s; // usual exception constructors } void delegate(Status) onError = (Status s) { throw new StatusException(s);}; I get a error like cannot initialise something that needs a context at compile time. Ignoring the fact the the initialiser does not need a context, if I do void delegate(Status) onError; static this() { onError = (Status s) { throw new StatusException(s);}; } void main() { import std.stdio; writeln(onError.funcptr); // null } WAT? 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); } output: null 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
Sep 29 2017
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/32LDC 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); } ---
Sep 30 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: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.No "initialising onError", the static this is not even being run! I'm using LDC master. See also https://github.com/libmir/dcompute/issues/32LDC 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); } ---
Sep 30 2017
On Saturday, 30 September 2017 at 12:07:21 UTC, Nicholas Wilson wrote: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.[The object needs to be pulled in during linking.]
Sep 30 2017