digitalmars.D - Asserting that a reference is valid
- Brad Beveridge <brad.beveridge somewhere.com> Jul 26 2004
- Derek Parnell <derek psych.ward> Jul 26 2004
- Brad Beveridge <brad.beveridge somewhere.com> Jul 26 2004
- Ilya Minkov <minkov cs.tum.edu> Jul 26 2004
- "Vathix" <vathixSpamFix dprogramming.com> Jul 26 2004
- "C. Sauls" <ibisbasenji yahoo.com> Jul 26 2004
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 Brad
Try 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 Brad
Try 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:Is there another way that I can assert that o is a valid reference
use it?
assert(o); -eye
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
Vathix wrote:"Ilya Minkov" <minkov cs.tum.edu> wrote in messageassert(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.
You could always do: assert(o !== null && o); But that's kind of... well, ugly, to me. -Chris S. -Invironz
Jul 26 2004









Brad Beveridge <brad.beveridge somewhere.com> 