Member access of __gshared global object

Puming via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 5 21:14:50 PDT 2014


On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote:
> On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote:
>> 1. Are AAs reference type? if so, why does the compiler copy 
>> it?
>
> This is probably your problem. They are reference types, but 
> initially that reference is `null`. When you write:
>
>     auto cmds = CONFIG.commands;
>
> `cmds` contains a copy of the `null` value. On assignment, the 
> actual AA is created, and assigned to `cmds`, but not back to 
> `CONFIG.commands`. Try initializing the AA in your class 
> constructor.

I checked the code and could concur your suggestion.

What I found strange were:

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?

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.



More information about the Digitalmars-d-learn mailing list