Rectangular or 2d associative arrays

Falk Henrich schreibmalwieder at hammerfort.de
Fri Mar 16 09:50:24 PDT 2007


David Freitas wrote:

>          int[char] x;         // Visually: = ['a':1, 'b':2] // associative
>          array x['b'] = 123;
>          writefln(x);  // this prints out: [b:2063597568]
>          writefln(x['b']); // this prints out: 123
> 
> This just doesn't seem intuitive to me? Why is there a "garbage" value
> being printed out?

What would you expect D to print out? How can the language know how to
interpet arrays of some type? Hard coding some special output format for
all types of arrays into the language is not a wise idea.

Falk



More information about the Digitalmars-d-learn mailing list