why static array can be reassigned with new allocation?

Paul Backus snarwin at gmail.com
Sun Oct 16 14:19:55 UTC 2022


On Sunday, 16 October 2022 at 11:47:35 UTC, mw wrote:
> That is not excuse to mix two different semantics into one 
> syntax.
>
> Especially D has `static if`.

The exact same "semantic mixing" also occurs between classes and 
structs:

     class C
     {
         int n;
         this(int n) { this.n = n; }
     }

     struct S
     {
         int n;
     }

     void main()
     {
         C c1 = new C(123);
         C c2;
         c2 = c1;
         c1.n = 456;
         assert(c2.n == 456); // "var reassignment"

         S s1 = S(123);
         S s2;
         s2 = s1;
         s1.n = 456;
         assert(s2.n == 123); // "content reassignment"
     }

Should we also have two separate syntaxes for these assignments?


More information about the Digitalmars-d mailing list