[Mono-devel-list] Comparing against null

Joe Ante joe at otee.dk
Thu Apr 7 12:56:59 EDT 2005


> Yes, that is correct. On csc x == null *always* does a pointerwise
> comparison. I made mcs do this. In some ways it is an optimization (the
> user one will at the very least require a function call), in others a
> correctness (though that seems very pendantic -- I am not sure if there
> are any real life examples where it makes a difference).
In our game engine we wrap C++ objects with small mono objects.
The C++ representation might be destroyed. We use a lot of weak referencing
and I want it to be straightforward to use.
Comparing against null is the obvious way to do that.

When invoking a member method of a C# wrapper this will always generate an
exception anyway. So i need some way to check if the actual C++ referenced
object is still around.

> If you absolutely need it, have a static readonly variable with the
> value of null. However, I'd advise that your equals impl only return
> `true' for the equality of null to another null.
In the general case i agree but i think for what we are doing it makes
obvious sense to compare against nulll and return true if the C++
representation is not around anymore, since it will generate exceptions if
you use it anyway.

Joachim Ante





More information about the Mono-devel-list mailing list