Returning variable-sized stack data

monkyyy crazymonkyyy at gmail.com
Wed Jul 17 13:50:01 UTC 2024


On Wednesday, 17 July 2024 at 08:23:45 UTC, IchorDev wrote:
> On Monday, 15 July 2024 at 17:20:57 UTC, monkyyy wrote:
>> I think you should also preemptively handle runtime stack 
>> allocated arrays inside the function
>>
>> ```d
>> int[$] foo(size_t i){
>>   int[i] output;
>>   foreach(...){
>>     ...
>>   }
>>   return output;
>> }
>> ```
>
> Oh yes, that would be fantastic!
> It'd be lowered to something like this, right?
> ```d
> int[] output = (cast(int*)alloca(i * int.sizeof))[0..i];
> ```

I have no idea, Im just saying it seems incomplete to have it 
only be returns; because they hack im imagining to make a, lets 
say, 0..10 element array where the magic is at the return call, 
will be some awful static foreach in a switch statement or some 
recursive functional meme.


More information about the dip.ideas mailing list