Empty associative array crashes program

Jonathan M Davis jmdavisProg at gmx.com
Tue Apr 2 00:10:08 PDT 2013


On Monday, April 01, 2013 23:44:43 Timothee Cour wrote:
> can we officially use
> 
> assert(a);
> 
> instead of
> 
> assert(a !is null);
> 
> (likewise with if(...))
> 
> It seems to compile and work just fine, and is shorter.

That depends on what a is. If it's an AA as in the OP, then yes, they should 
be the same. The same goes for a pointers to built-in types and arrays, but 
for classes and pointers to structs, assert(a) checks for null and then calls 
the class' invariant rather than just checking for null. However, the 
invariant does not get called for if statements.

- Jonathan M Davis


More information about the Digitalmars-d mailing list