DIP1000 scope inference proposal

Walter Bright newshound2 at digitalmars.com
Thu Oct 27 23:32:50 UTC 2022


On 10/27/2022 2:36 AM, German Diago wrote:
> As a person who has used D but not extensively, I was suprised of type[] vs 
> type[N] behavior all the time. I agree that [1, 2, 3] should allocate in the 
> stack but I am not sure how much code that could break? For example, if before 
> it was on the heap, what happens with this now?

You'll get an error on [1]

> int [] func() {
>    // Allocated in the stack, I presume that not safe, should add .dup?
>    int[] v  = [1, 2, 3];
>    return v;  [1]
> }
> 
> How it should work?

Add .dup for those that need the array to survive the function.



More information about the Digitalmars-d mailing list