Top 5

Benji Smith dlanguage at benjismith.net
Fri Oct 10 17:07:17 PDT 2008


Robert Fraser wrote:
> Benji Smith wrote:
>> Jarrett Billingsley wrote:
>>> On Fri, Oct 10, 2008 at 11:54 AM, Benji Smith 
>>> <dlanguage at benjismith.net> wrote:
>>>
>>>>> new T[x] is a brain-dead syntax that I wish Walter hadn't imported 
>>>>> in the
>>>>> first place.
>>>> Really? I think it's very valuable.
>>>>
>>>> The "new T[x]" syntax lets you construct an array as an RValue. 
>>>> Without that
>>>> syntax, you have to declare an array before using it.
>>>
>>> No, what he's getting at is that "new T[x]" does not mean "allocate a
>>> statically-sized array", it means "allocate a dynamically-sized
>>> array".  "new T" for any T should mean "allocate a T", not "allocate
>>> something that's kind of close to a T."
>>
>> As long as T[3] and T[5] and T[] are considered different types, I 
>> agree  with that sentiment.
>>
>> But then again, I think array semantics would make a lot more sense if 
>> all arrays were of type T[], regardless of their size, their location 
>> (stack vs heap), and whether they're static or dynamic.
>>
>> --benji
> 
> Static arrays are needed for C compatibility (in extern(C) structs), so 
> they're not going anywhere.

So what? Null-terminated strings are also necessary for C compatibility, 
   but that doesn't mean *all* strings should be null terminated.

Anyhow, I'm not going to keep chasing this point. For people new to D, 
the subtle differences between static and dynamic arrays can be a source 
of confusion. I still have my share of gotcha moments with them, and I 
think D would be well served by minimizing those differences.

--benji



More information about the Digitalmars-d mailing list