How to check for null references

Jascha Wetzel "[firstname]" at mainia.de
Mon Aug 27 05:40:58 PDT 2007


Hans-Eric Grönlund wrote:
> Hi all!
> 
> I'm trying to learn D, mostly by trial and error, and I keep tripping over the smallest rocks. This time the pebble is:
> How can I gracefully check if an object reference is null? I get an access violation if I try this and the reference (o) is null:
> 
> if (o == null) {...}
> 
> Is this a bug in DMD (I use the stable 1.x version) or did I miss something obvious?
> 
> Best regards
> 
> Hans-Eric Grönlund
> Software Developer, Project Manager, Freelance Journalist
> http://www.hans-eric.com/

the "==" operator can be overloaded and D implicitly dereferences 
pointers to structs/classes, therefore the identity operator "is" and 
"!is" has to be used.



More information about the Digitalmars-d mailing list