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

Dmitry Olshansky dmitry.olsh at gmail.com
Thu May 16 15:03:57 PDT 2013


16-May-2013 13:31, Maxim Fomin пишет:
> On Thursday, 16 May 2013 at 09:05:46 UTC, Dicebot wrote:
>> On Wednesday, 15 May 2013 at 19:30:41 UTC, Dmitry Olshansky wrote:
>>> Won't this work?
>>> *cast(void**)&object
>>
>> Right question is "is this guaranteed to work by spec?".
>
> Spec is silent about this but in practice this should work. Real
> question is here why would you want "pointer to class" when you have
> normal reference and what such "pointer" would give you.

Since class is a reference it's a pointer value (address anyhow).
Hence you'll get an address of value holding that address (e.g. of a 
temporary) then dereference it as void** pointer.

It's sometimes useful in this particular case to circumvent type-system 
in order to do smth (interface with C etc.).



-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list