void initialization of class fields
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Aug 7 18:28:22 PDT 2010
This is a modified example from TDPL, page 185-186, although I've increased the size of the array here:
class Transmogrifier
{
double[512] alpha = void;
size_t usedAlpha;
this()
{
}
}
void main()
{
auto t = new Transmogrifier;
writeln(t.alpha);
}
This will write 512 zeros in my case. If I understood correctly, then alpha is an array containing 512 uninitialized values. Which is confusing me as to why I'm getting back zeros.
If this was C (minus the classes), I'd get back random values at random locations in memory until I stepped into the wrong place, which would hopefully terminate my app.
I guess I need a primer in how D manages memory, is what I'm really saying. :)
More information about the Digitalmars-d
mailing list