arrays: if(null == [ ])
Steven Schveighoffer
schveiguy at yahoo.com
Mon May 14 12:53:20 PDT 2012
On Mon, 14 May 2012 15:30:25 -0400, deadalnix <deadalnix at gmail.com> wrote:
> Le 14/05/2012 16:37, Steven Schveighoffer a écrit :
>> Note that [] is a request to the runtime to build an empty array. The
>> runtime detects this, and rather than consuming a heap allocation to
>> build nothing, it simply returns a null-pointed array. This is 100% the
>> right decision, and I don't think anyone would ever convince me (or
>> Andrei or Walter) otherwise.
>>
>
> Obviously this is the right thing to do !
>
> The question is why an array of length 0 isn't nulled ? It lead to
> confusing semantic here, and can keep alive memory that can't be
> accessed.
int[] arr;
arr.reserve(10000);
assert(arr.length == 0);
-Steve
More information about the Digitalmars-d
mailing list