arrays: if(null == [ ])
Steven Schveighoffer
schveiguy at yahoo.com
Wed May 16 06:18:38 PDT 2012
On Mon, 14 May 2012 18:07:24 -0400, Timon Gehr <timon.gehr at gmx.ch> wrote:
> On 05/14/2012 01:51 PM, deadalnix wrote:
>> Le 14/05/2012 12:49, Gor Gyolchanyan a écrit :
>>> So, null arrays and empty arrays are always the same, except for an
>>> empty string, which is a valid non-nill array of characters with length
>>> 0, right?
>>>
>>
>> If it is the current behavior, it deserve a WAT !
>
> I agree, but it is explained easily. Built-in string literals are always
> zero-terminated, therefore an empty string literal must point into
> accessible memory. I'd like to have [] !is null as well, so that null
> can reliably be used as a sentinel value.
This would mean either a) allocating memory for a 0 length array, or b)
pointing it at non-null but non-heap memory.
a) is certainly out of the question.
b) is possible, but I still think we should discourage using null as a
sentinel, it leads to confusing code.
Regardless, we should fix if(!arr) to mean if(!arr.length).
-Steve
More information about the Digitalmars-d
mailing list