[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mono-devel-list
Subject:    Re: [Mono-devel-list] Comparing against null
From:       Joe Ante <joe () otee ! dk>
Date:       2005-04-07 16:56:59
Message-ID: BE7B32FB.21F22%joe () otee ! dk
[Download RAW message or body]

> 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



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic