No segfault -> null == ""

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Mar 31 08:33:37 PDT 2009


Unknown W. Brackets wrote:
> In the case of arrays, "test == null" and "test 
> is null" should be the same operation.

They're not the same operation. (Though there was quite a large debate on these 
newsgroups a while back because a lot of people thought they *should* be, as you 
said)

The difference:
'==', when used on arrays, compares first the length and then all elements (only 
if the lengths are equal, otherwise the result is already known).
Since 'null' contains no elements, only the length gets compared for (null == 
test). Either the other array is also empty and they're therefore equal, or the 
other array isn't and they aren't.
'is', when used on arrays, compares both the length and the pointer. It only 
returns true if both are equal. It never looks at the elements.

So (null == ""), but (null !is "").


More information about the Digitalmars-d-learn mailing list