"is null" vs "== null"
Lionello Lunesu
lio at remove.lunesu.com
Mon Mar 27 01:45:49 PST 2006
> I'll venture to say that most people will expect that null == null, and at
> the very least, it seems that many (most?) people on the NG agree.
What about the general case: ptr == ptr (which includes the case where
ptr==null: null == null)? Should the compiler inhibit the call to opEquals
in the general case as well?
But settling this issue will not settle case where one of the arguments to
"==" is null. I saw some opEquals implementation somewhere that started with
the line "if (o is null) return false;", which seems silly, since if the
opEquals would have been called the other way around (b == a, instead of a
== b) then the program would have surely crashed (being a virtual call,
"this" must be valid to access the virtual function table). Right? "a==b"
should in any case be identical to "b==a".
I guess the only thing we can agree on is that the compiler should emit an
error message when it encounters code like "if (whatever == null)" or "if
(null == whatever)".
L.
More information about the Digitalmars-d
mailing list