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

Artur Skawina art.08.09 at gmail.com
Wed May 15 08:08:33 PDT 2013


On 05/15/13 13:04, Dicebot wrote:
> On Wednesday, 15 May 2013 at 10:31:29 UTC, David wrote:
>>> "&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

   class C { auto opCast(T:void*)() { return null; } }

So - no - a simple cast to void* won't always work, as the op can be
overloaded, even if only by accident. 

See also:
http://forum.dlang.org/thread/mutvhrrdfzunbrhmvztp@forum.dlang.org#post-mailman.2432.1354406246.5162.digitalmars-d-learn:40puremagic.com
and
http://d.puremagic.com/issues/show_bug.cgi?id=8545


artur


More information about the Digitalmars-d-learn mailing list