Why are immutable array literals heap allocated?
ag0aep6g
anonymous at example.com
Sat Jul 6 09:56:57 UTC 2019
On 06.07.19 01:12, Patrick Schluter wrote:
> On Friday, 5 July 2019 at 23:08:04 UTC, Patrick Schluter wrote:
>> On Thursday, 4 July 2019 at 10:56:50 UTC, Nick Treleaven wrote:
>>> immutable(int[]) f() @nogc {
>>> return [1,2];
>>> }
[...]
>
> and it cannot optimize it away because it doesn't know what the caller
> want to do with it. It might in another module invoke it and modify it,
> the compiler cannot tell. auto a=f(); a[0]++;
f returns immutable. typeof(a) is immutable(int[]). You can't do a[0]++.
More information about the Digitalmars-d-learn
mailing list