digitalmars.D - Asserting that a reference is valid
- Brad Beveridge (9/9) Jul 26 2004 Hi all, this sounds like a daft question, but I can't find in the docs w...
- Derek Parnell (12/23) Jul 26 2004 Try
- Brad Beveridge (5/31) Jul 26 2004 Thank you, now that I see the === operator it rings a bell :) It has be...
- Ilya Minkov (3/5) Jul 26 2004 assert(o);
Hi all, this sounds like a daft question, but I can't find in the docs where it is addressed. The following code on linux with dmd0.94 segfaults. Object o; assert (o != null); Is there another way that I can assert that o is a valid reference before I use it? Cheers Brad
Jul 26 2004
On Mon, 26 Jul 2004 19:41:19 +1200, Brad Beveridge wrote:Hi all, this sounds like a daft question, but I can't find in the docs where it is addressed. The following code on linux with dmd0.94 segfaults. Object o; assert (o != null); Is there another way that I can assert that o is a valid reference before I use it? Cheers BradTry assert (o !== null) or assert (!(o === null)); or assert (!(o is null)); -- Derek Melbourne, Australia 26/Jul/04 5:43:18 PM
Jul 26 2004
Thank you, now that I see the === operator it rings a bell :) It has been a long time since I read the D specs in fine detail. Cheers Brad Derek Parnell wrote:On Mon, 26 Jul 2004 19:41:19 +1200, Brad Beveridge wrote:Hi all, this sounds like a daft question, but I can't find in the docs where it is addressed. The following code on linux with dmd0.94 segfaults. Object o; assert (o != null); Is there another way that I can assert that o is a valid reference before I use it? Cheers BradTry assert (o !== null) or assert (!(o === null)); or assert (!(o is null));
Jul 26 2004
Brad Beveridge schrieb:Is there another way that I can assert that o is a valid reference before I use it?assert(o); -eye
Jul 26 2004
"Ilya Minkov" <minkov cs.tum.edu> wrote in message news:ce2qo1$quf$3 digitaldaemon.com...Brad Beveridge schrieb:before IIs there another way that I can assert that o is a valid referenceThat's a special case that calls the invariant on the object. If it's null, you'll get an access violation. I wish a simple o!==null would be automatically tested before the invariant, but oh well.use it?assert(o); -eye
Jul 26 2004
Vathix wrote:"Ilya Minkov" <minkov cs.tum.edu> wrote in messageYou could always do: assert(o !== null && o); But that's kind of... well, ugly, to me. -Chris S. -Invironzassert(o);That's a special case that calls the invariant on the object. If it's null, you'll get an access violation. I wish a simple o!==null would be automatically tested before the invariant, but oh well.
Jul 26 2004