constant expression

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 23 00:00:24 PST 2016


On Tuesday, 23 February 2016 at 07:43:37 UTC, Ali Çehreli wrote:
> On 02/22/2016 11:38 PM, Nicholas Wilson wrote:
>
>> I've tried with both mutable and immutable a module scope. 
>> Scope I want
>> is global (don't care about mutability)
>>
>
> Uncomment immutable if you want immutable and remove 'shared' 
> if you want multiple of this per thread (probably not).
>
> /* immutable */ string[string] ctodtypes;
>
> shared static this() {
>     ctodtypes =
>     [
>         "void"      : "void",
>         "uint32_t"  : "uint",
>         "uint64_t"  : "ulong",
>         "int32_t"   : "int",
>         "int64_t"   : "long",
>         "char"      : "char",
>         "uint8_t"   : "ubyte",
>         "size_t"    : "size_t",
>         "float"     : "float"
>      ];
> }
>
> void main() {
>     ctodtypes["hello"] = "world";
> }
>
> Ali

Thanks

Silly question. Why is this necessary?


More information about the Digitalmars-d-learn mailing list