Member access of __gshared global object

Dragos Carp via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 6 07:22:30 PDT 2014


>
> 1. The only way that I can initialize it is to assign a value. 
> But I want to initialize an empty AA, is that possible?

Like arrays, associative arrays have value semantics. This means 
that they can be always referenced.

It is easier to see this with an array:

int[] a1 = null;
writeln(a1.ptr);
writeln(a1.length);

will print "null" and 0;

The array is in fact a pair: ptr and length. The pair is 
allocated like any other primitive or struct and thus cannot be 
null.

This means if you want an empty AA you can write

aa1 = null;

or more explicit

aa1 = typeof(aa1).init;

>
> 2. CONFIG.commands is not `null` before initialized, it is 
> '[]'(when I writeln it). But it still behave like what you 
> described (except that it won't produce an NullPointer 
> Exception.

See 1.


More information about the Digitalmars-d-learn mailing list