On Thu, Aug 07, 2014 at 02:00:27AM +0000, Puming via Digitalmars-d-learn wrote: > On Wednesday, 6 August 2014 at 15:42:05 UTC, Marc Schütz wrote: [...] > >Indeed, it was just what the OP suspected as the culprit. > > You are right, I didn't know about the AA initialization problem then. > > When I writln the AA and it outputs '[]', I thought it was > initialized, which in that case was actually null. [...]
This is a known gotcha with AA's and built-in arrays: they are null until you insert something into them, which means that while they are null, passing them into functions that add stuff to them won't update the original references because there is no common object that null points to. But once they become non-empty, passing them around to functions that change their contents will affect what's seen through the original references, since now they are pointing at a common object in memory. So they behave like value types when null, but acquire reference semantics once they are non-empty. This can be rather confusing for newbies. T -- Ignorance is bliss... until you suffer the consequences!