auto arr = [1, 2, 3] should be a static array, not a GC allocated array
bachmeier
no at spam.net
Thu Jul 14 17:33:22 UTC 2022
On Thursday, 14 July 2022 at 15:26:44 UTC, Dave P. wrote:
> On Thursday, 14 July 2022 at 14:51:01 UTC, bachmeier wrote:
>> On Thursday, 14 July 2022 at 13:14:59 UTC, ryuukk_ wrote:
>>> It is misleading, nobody expect this to be GC allocated
>>>
>>> It should be equal to:
>>>
>>> ```D
>>> int[3] arr = [1, 2, 3]
>>> ```
>>>
>>> Also why it is GC allocated without requiring ``new``?
>>
>>> nobody expect this to be GC allocated
>>
>> Maybe I'm not fully awake, but why would anyone expect this to
>> *not* be GC allocated?
>
> Similar syntax in C is for a static array of inferred length:
>
> ```C
> int arr[] = {1,2,3};
> ```
>
That would be a potential justification. OP claims nobody would
expect a dynamic array, though, and matching C's behavior hardly
makes the design choice obvious.
> D has no way to express a similar concept without being
> horribly verbose with `.staticArray`.
OP wanted it to act the same as `int[3] arr = [1, 2, 3]`, so
clearly there is.
More information about the Digitalmars-d
mailing list