Top 5
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Oct 8 16:25:03 PDT 2008
Sean Kelly wrote:
> 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.
The problem with alloca is that it's not "encapsulatable"---Walter must
love this because he thrives on "evaluatable"---because you can't
squirrel the call to alloca in a function that takes care of the casting.
Andrei
More information about the Digitalmars-d
mailing list