why static array can be reassigned with new allocation?
mw
mingwu at gmail.com
Sun Oct 16 01:54:51 UTC 2022
On Sunday, 16 October 2022 at 00:27:56 UTC, Paul Backus wrote:
> On Saturday, 15 October 2022 at 20:05:25 UTC, mw wrote:
>> While the 1st statement should just be var assignment, which
>> does NOT need to check length at all, the error message should
>> be "Error: static array cannot be re-assigned".
>
> Static arrays can be reassigned, though:
>
> int[3] a = [1, 2, 3];
> int[3] b = [4, 5, 6];
> b = a;
> a[0] = 4;
> assert(b == [1, 2, 3]);
From the context of this discussion thread, "var reassign" to
static array means: change a.ptr to where it pointing to, i.e the
address. And "content assignment" means: change the content of
the array (but not the a.ptr, the address).
You example here is "content assignment".
My main point is these two different assignments shouldn't use
the same syntax, regardless they are static or dynamic array.
More information about the Digitalmars-d
mailing list