Forbid dynamic arrays in boolean evaluation contexts

Steven Schveighoffer schveiguy at yahoo.com
Tue Mar 26 10:36:15 PDT 2013


On Tue, 26 Mar 2013 13:32:02 -0400, Jonathan M Davis <jmdavisProg at gmx.com>  
wrote:

> On Tuesday, March 26, 2013 12:24:56 Vladimir Panteleev wrote:
>> [] (the literal) has .ptr as null. That may or may not be a bug.
>
> As I understand it, it's very much on purpose. It avoids a needless  
> memory
> allocation.

That is correct.  Since null and non-null-but-empty arrays are essentially  
equivalent, it would be wasteful to allocate a new block for 0 bytes.   
Same as if you did new T[0].

-Steve


More information about the Digitalmars-d mailing list