arrays: if(null == [ ])

Simen Kjaeraas simen.kjaras at gmail.com
Mon May 14 03:26:49 PDT 2012


On Mon, 14 May 2012 12:08:17 +0200, Gor Gyolchanyan  
<gor.f.gyolchanyan at gmail.com> wrote:

> Hi! I have a small question:
> Is the test for a null array equivalent to a test for zero-length array?
> This is particularly interesting for strings.
> For instance, I could return an empty string from a toString-like  
> function
> and the empty string would be printed, but If I returned a null string,
> that would indicate, that there is no string representation and it would
> cause some default string to be printed.
> So, the question is, if a null array is any different from an empty  
> array?
>

The two are different, yes. [] == null actually compares length. If you
want to know if the length is zero, use arr.length. If you want to know if
it points to null, check if arr.ptr is null.


More information about the Digitalmars-d mailing list