<html>
<head>
<base href="http://bugzilla.gdcproject.org/" />
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW - cc1d locks up when specifying function instead of function pointer in an array"
href="http://bugzilla.gdcproject.org/show_bug.cgi?id=178#c5">Comment # 5</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW - cc1d locks up when specifying function instead of function pointer in an array"
href="http://bugzilla.gdcproject.org/show_bug.cgi?id=178">bug 178</a>
from <span class="vcard"><a class="email" href="mailto:ketmar@ketmar.no-ip.org" title="Ketmar Dark <ketmar@ketmar.no-ip.org>"> <span class="fn">Ketmar Dark</span></a>
</span></b>
<pre>see the part about CTFE here: <a href="http://dlang.org/function.html#interpretation">http://dlang.org/function.html#interpretation</a>
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are watching all bug changes.</li>
</ul>
</body>
</html>