String to boolean inconsistency

Simen kjaeraas simen.kjaras at gmail.com
Sat Dec 11 19:07:16 PST 2010


Simen kjaeraas <simen.kjaras at gmail.com> wrote:

> Ellery Newcomer <ellery-newcomer at utulsa.edu> wrote:
>
>> I forget, why are we supposed to use is instead of == with null?
>
> '[] is null' compares ptr and length, while '[] == null' compares only
> the length. Weirdly though, '[] is null' is false for ptr == 0,
> length != 0. Not likely to happen much in practice.

To actually answer your question, == calls opEquals for classes, and
that is called on both lhs and rhs. null.opEquals however, segfaults.

is, on the other hand, compares pointer equality, without caring for the
details of what opEquals wants to do.

-- 
Simen


More information about the Digitalmars-d mailing list