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

David d at dav1d.de
Wed May 15 03:31:29 PDT 2013


Am 14.05.2013 14:24, schrieb Dicebot:
> 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.
> 
> "&c" is address of reference, no class instance. I don't know if there
> is a way to get a pointer to class instance in D but I am not aware of one.

A simple cast to void* should do it: cast(void*)c


More information about the Digitalmars-d-learn mailing list