Comment # 5 on bug 178 from
see the part about CTFE here: http://dlang.org/function.html#interpretation

one of the features of D is that it can run code in *compile* *time* (hence the
"CTFE" term — it's "Compile Time Function Evaluation"). compiler can run D code
while compiling your source and use the result to initialise variables.

in your case compiler tries to evaluate `Reset_Handler()` and use it's return
value to init array element. it's a very powerful feature, as you can calculate
various tables without resorting to external "generators". i, for example,
using that to generate parity flag table in my Z80 emulator:

auto genParityTable () {
  ubyte[256] t;
  foreach (immutable f; 0..256) {
    int n, p;
    for (n = f, p = 0; n != 0; n >>= 1) p ^= n&0x01;
    t[f] = (p ? 0 : 1);
  }
  return t;
}
private immutable ubyte[256] tblParity = genParityTable();

here compiler executes `genParityTable()` when it compiling my code and using
it's result to init `tblParity`.

it's vital to understand that `tblParity` is initialized in COMPILE time, there
is no runtime function calls.

the power of D, yeah.


You are receiving this mail because: