Top 5

Sean Kelly sean at invisibleduck.org
Wed Oct 8 15:59:20 PDT 2008


Andrei Alexandrescu wrote:
> Denis Koroskin wrote:
> 
>> [Wish] Stack allocation - why allocate on heap when you can allocate 
>> on stack?
>>
>> void drawString(char[] text) {
>>     int length = getLengthAsUtf16String(text); // for leading zero
>>     wchar[length + 1] buffer;                  // C++ and C++0x both 
>> have this feature
>>     convertToUtf16String(text, buffer); buffer[length] = 0;
>>     graphics.DrawString(font, color, buffer.ptr);
>> }
>>
>> Do you write down? :)
>> Thanks.
> 
> Neither C++ nor C++0x have that feature. C99 does (VLAs). But I do think 
> it's a useful feature. In a class I taught that entailed teaching 
> students some C, most of them actually tried VLAs naturally without 
> knowing about it, gcc accepted it, and they used it to great effect.

We can generally use alloca for this in D, so I don't consider this a 
major issue.  Be pretty cool to have it in-language though.


Sean



More information about the Digitalmars-d mailing list