Is empty array null?

Steven Schveighoffer schveiguy at yahoo.com
Mon Mar 5 07:25:09 PST 2012


On Mon, 27 Feb 2012 15:44:40 -0500, Pedro Lacerda <pslacerda at gmail.com>  
wrote:

> The expression "[] is null" evaluates to true here using 2.058, but I
> expected to be false. What am I missing?

The runtime is asked to allocate an empty array.  Instead of consuming  
heap space creating a block with no data in it, it simply returns a null  
array which is a valid empty array.

You should try not to make your code dependent on whether an array pointer  
is null or not.  A null and empty array are for the most part  
interchangeable.  The only place where they differ is when you check to  
see if the pointer is null.

-Steve


More information about the Digitalmars-d-learn mailing list