Thread overview | |||||
---|---|---|---|---|---|
|
August 28, 2014 How to cast to "void*", while bypassing alias this or opCast | ||||
---|---|---|---|---|
| ||||
I'm investigating a phobos regression. From "doesPointTo": //---- static if (isPointer!S || is(S == class) || is(S == interface)) { const m = cast(void*) source; //---- Basically, given a "pointer like" structure, I want the void* equivalent. I really don't care about how "S" works, and am "observing" the "source" object as nothing more than a bag of member fields. The issue though is that it turns out that such code can and will call either opCast or alias this, which is *not* what we want at all in this piece of code. Is there any way to do a "hard" reinterpret cast in such a situation? |
August 28, 2014 Re: How to cast to "void*", while bypassing alias this or opCast | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | On Thursday, 28 August 2014 at 10:45:52 UTC, monarch_dodra wrote:
> I'm investigating a phobos regression. From "doesPointTo":
>
> //----
> static if (isPointer!S || is(S == class) || is(S == interface))
> {
> const m = cast(void*) source;
> //----
>
> Basically, given a "pointer like" structure, I want the void* equivalent. I really don't care about how "S" works, and am "observing" the "source" object as nothing more than a bag of member fields.
>
> The issue though is that it turns out that such code can and will call either opCast or alias this, which is *not* what we want at all in this piece of code.
>
> Is there any way to do a "hard" reinterpret cast in such a situation?
*cast(void**)&source
|
August 28, 2014 Re: How to cast to "void*", while bypassing alias this or opCast | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Thursday, 28 August 2014 at 11:02:03 UTC, anonymous wrote:
> On Thursday, 28 August 2014 at 10:45:52 UTC, monarch_dodra wrote:
>> I'm investigating a phobos regression. From "doesPointTo":
>>
>> //----
>> static if (isPointer!S || is(S == class) || is(S == interface))
>> {
>> const m = cast(void*) source;
>> //----
>>
>> Basically, given a "pointer like" structure, I want the void* equivalent. I really don't care about how "S" works, and am "observing" the "source" object as nothing more than a bag of member fields.
>>
>> The issue though is that it turns out that such code can and will call either opCast or alias this, which is *not* what we want at all in this piece of code.
>>
>> Is there any way to do a "hard" reinterpret cast in such a situation?
>
> *cast(void**)&source
Hum... now I feel retarded.
In my mind I had "I want re-interpret, not address of, so no operator&".
Thanks.
|
Copyright © 1999-2021 by the D Language Foundation