void initialization of class fields
Steven Schveighoffer
schveiguy at yahoo.com
Sat Aug 7 19:01:41 PDT 2010
On Sat, 07 Aug 2010 21:28:22 -0400, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> 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. :)
I don't know if that works. The code to initialize a class simply copies
the class initializer value from the classinfo. If it obeyed your
command, it would have to initialize only part of the class, skipping the
part in the middle.
-Steve
More information about the Digitalmars-d
mailing list