cast(size_t)&c != 0, but c is null

Andrej Mitrovic andrej.mitrovich at gmail.com
Tue May 14 05:19:59 PDT 2013


On Tuesday, 14 May 2013 at 12:18:20 UTC, simendsjo wrote:
> Very newbie question coming up :)
>
> How does D mark null values for classes?
> `c is null` returns true, but `&c` isn't 0.
> So how does D know `c is null`?
>
> class C {}
> C c;
> assert(c is null);
> assert(cast(size_t)&c == 0); // fails.

That's the address of the reference. If you want the address of 
the object:

assert(cast(size_t)cast(void*)c == 0); // passes


More information about the Digitalmars-d-learn mailing list