why static array can be reassigned with new allocation?

mw mingwu at gmail.com
Sun Oct 16 12:03:32 UTC 2022


On Sunday, 16 October 2022 at 11:50:02 UTC, Mike Parker wrote:
> On Sunday, 16 October 2022 at 11:47:35 UTC, mw wrote:
>> On Sunday, 16 October 2022 at 09:04:59 UTC, Nick Treleaven 
>> wrote:
> .
>>>
>>> A static array doesn't have a ptr runtime field.
>>
>> Someone showed this code very earlier in this thread already:
>>
>>
>> void main() {
>>      int[3] arr;
>>      writeln(arr.ptr);
>> }
>>
>> Output:
>> 7FFC1A072820
>>
>>
>
> Keyword: "runtime". Try to assign a new value to the `.ptr` 
> property and see what happens.

Well, I printed it at "runtime".


Again, I know that, and I want the compiler to help me catch the 
problem in my OP example.


Even if you mean "modifiable" at runtime, dynamic array's .ptr 
behaves the same:

void main() {
      int[] arr;
      arr.ptr = 0;
      writeln(arr.ptr);
}

onlineapp.d(5): Error: `arr.ptr` is not an lvalue and cannot be 
modified





More information about the Digitalmars-d mailing list