Run-time initialised static variables

dekevin dekevin at student.ethz.ch
Tue Feb 6 23:03:07 UTC 2018


Hello everyone,
I just ran into the problem, that I need a static variable, where 
the initialisation code for that variable is only accessible 
during run-time (since part of the initialisation code will be 
dynamically linked).

Is there a way to do this in D?

To be a bit more concrete, this is where I have the problem 
(where ℚ uses GMP, which is dynamically linked):

struct ℚInf {
    ℚ qval;
    immutable static ℚInf zero = ℚInf(0,1);
    this(long num, long den) {
         qval = ℚ(num,den); //this initialisation requires 
dynamically linked code
     }
}


More information about the Digitalmars-d-learn mailing list