www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to cast to "void*", while bypassing alias this or opCast

reply "monarch_dodra" <monarchdodra gmail.com> writes:
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?
Aug 28 2014
parent reply "anonymous" <anonymous example.com> writes:
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
Aug 28 2014
parent "monarch_dodra" <monarchdodra gmail.com> writes:
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.
Aug 28 2014