Avoid compile time evaluation

Andrea Fontana nospam at example.com
Fri Apr 13 05:52:05 PDT 2012


If I have something like:

static int var = myFunction();

dmd will evaluate myFunction() at compile time. If it can't, it 
gives me a compile error, doesn't it? If I'm not wrong, static 
force this.

If i don't use static, dmd will try to evaluate myfunction() at 
compile time, and if it can't, myfunction() will be executed at 
runtime, right?

So I have a code like this:

...
// Here some code to debug/fix...
// Here some code to debug/fix...
// Here some code to debug/fix...
// Here some code to debug/fix...
...
static int var = myVeryVeryComplexFunction();

If i have to work to some code before my complex function, every 
time I have to re-compile code, it takes a lot because dmd 
evalute at compile time myVeryVeryComplexFunction() also if i 
don't use static. Does a keyword to force runtime evaluation 
exists? I can't find any documentation (neither on static used in 
this way, any link?)...

My dirty way to do this is to edit myVeryVeryComplexFunction() 
adding a writeln() (or something similar) to function body.


More information about the Digitalmars-d-learn mailing list