Static associative array expressions

Stefan Koch uplink.coder at googlemail.com
Sun Sep 19 14:10:35 UTC 2021


On Sunday, 19 September 2021 at 11:39:15 UTC, pineapple wrote:
> This could be nice. It's always been kind of annoying having to 
> put AAs in static initializers and not being able to inspect 
> them at compile time.

Be careful though.
The runtime does not know if an array is in static memory or not.
(Though it would be trivial to add a flag so it knows.)
And Therefore when you do this:
```d
static mutable_ct_createdAA = mixin(["a","b"]);
```
and you mutate that array in any way.
The runtime will crash.
As it tries write into memory it is not supposed to write in.

That can be fixed by either:
- disallowing static mutable AAs for now. (my preferred option.)
- Or but adding a flag which would tell the Runtime to copy the 
literal into mutable memory and perform any modification in that 
memory. COW (copy on write) essentially.



More information about the Digitalmars-d mailing list