C++ cast to D cast Part 2
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sun Sep 23 06:50:08 PDT 2007
"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message
news:fd3tfr$8i6$2 at digitalmars.com...
> Jarrett Billingsley wrote:
>> "BLS" <nanali at nospam-wanadoo.fr> wrote in message
>> news:fd2v57$1ueb$1 at digitalmars.com...
>>
>>> CWin pActive = cast(CWin)cast(void*)
>>> cast(HWND)GetWindowLong(msg.hwnd,GWL_USERDATA);
>>
>> Yessir.
>
> Yes that's what I meant, but I have no idea if it works. It was just a
> guess. Jarrett you can confirm that that avoids the runtime check in the
> cast?
>
> --bb
class A
{
}
class B
{
}
void main()
{
A a = new A();
B b = cast(B)cast(void*)a;
B b2 = cast(B)a;
Stdout.formatln("{:X8} {:X8}", cast(void*)b, cast(void*)b2);
}
This prints out (something like)
0012AB60 00000000
So yes, the cast(B)cast(void*) avoids a runtime check.
More information about the Digitalmars-d-learn
mailing list