Thread overview
casting interface to void*
May 10, 2005
Ben Hinkle
May 10, 2005
Walter
May 10, 2005
Ben Hinkle
May 10, 2005
Walter
May 10, 2005
Walter, given an interface reference x can we make cast(void*)x actually
perform cast(void*)cast(Object)x? Similarly casting from void* to an
interface X would actually perform cast(X)cast(Object). That way interfaces
could be used as keys to assoc arrays and in general it would make
interfaces operate more uniformly with objects. Plus it would then be true
that
  Object obj = x;
  cast(void*)x === cast(void*)obj;


May 10, 2005
"Ben Hinkle" <ben.hinkle@gmail.com> wrote in message news:d5p4sc$6dk$1@digitaldaemon.com...
> Walter, given an interface reference x can we make cast(void*)x actually
> perform cast(void*)cast(Object)x? Similarly casting from void* to an
> interface X would actually perform cast(X)cast(Object). That way
interfaces
> could be used as keys to assoc arrays and in general it would make
> interfaces operate more uniformly with objects. Plus it would then be true
> that
>   Object obj = x;
>   cast(void*)x === cast(void*)obj;

I'm uneasy about doing that because then that removes the ability to just know what the actual pointer is.


May 10, 2005
"Walter" <newshound@digitalmars.com> wrote in message news:d5r00o$1m66$1@digitaldaemon.com...
>
> "Ben Hinkle" <ben.hinkle@gmail.com> wrote in message news:d5p4sc$6dk$1@digitaldaemon.com...
>> Walter, given an interface reference x can we make cast(void*)x actually
>> perform cast(void*)cast(Object)x? Similarly casting from void* to an
>> interface X would actually perform cast(X)cast(Object). That way
> interfaces
>> could be used as keys to assoc arrays and in general it would make
>> interfaces operate more uniformly with objects. Plus it would then be
>> true
>> that
>>   Object obj = x;
>>   cast(void*)x === cast(void*)obj;
>
> I'm uneasy about doing that because then that removes the ability to just know what the actual pointer is.

When would a D program need that? Can't they reconstruct the pointer from the classinfo if they really want to know the interface offset? If an interface is another view on an object one would imagine having the same pointer for the Object view as for the interface views would be desirable. The fact that interfaces require different pointers should be an implementation detail not visible to the user (preferably).


May 10, 2005
"Ben Hinkle" <bhinkle@mathworks.com> wrote in message news:d5r23j$1obd$1@digitaldaemon.com...
>
> "Walter" <newshound@digitalmars.com> wrote in message news:d5r00o$1m66$1@digitaldaemon.com...
> > I'm uneasy about doing that because then that removes the ability to
just
> > know what the actual pointer is.
>
> When would a D program need that?

I need it when debugging <g>. D needs to support ways to get at the underlying representation of things. The void* cast is how that's done with references.

> Can't they reconstruct the pointer from
> the classinfo if they really want to know the interface offset? If an
> interface is another view on an object one would imagine having the same
> pointer for the Object view as for the interface views would be desirable.
> The fact that interfaces require different pointers should be an
> implementation detail not visible to the user (preferably).

But it's an important detail. I think the functionality you need is
supported with the cast(Object).