DMD 0.161 release

BenHinkle BenHinkle_member at pathlink.com
Wed Jun 21 20:03:56 PDT 2006


>> Consider this:
>> 
>>   int can be implicitly converted to long.
>>   Therefore, shouldn't int[] be usable as a long[]?
>> 
>> It's an exactly analogous situation.
>
>No, it isn't. int is of a different "class" than long, while an 
>interface reference and a class reference point to exactly the same object.
>
>You also seem to miss the reduced complexity of implementation (a stated 
>goal I believe). With a simple double lookup, interfaces can be handled 
>in a single place, and I'd guess you could implement that very easily 
>just by faking another calling convention.

Can you explain more what you mean by double lookup? I'm not aware of that
technique.

>On the other hand, if interface references point to a different address 
>than class references, you need to store offsets somewhere, have to 
>modify the address on every call, need to handle implicit conversions 
>when passing function boundaries, etc. etc.

This technique I'm used to. It's called thunking and I believe it's the standard
way of implementing MI and/or interfaces. That is, when a class implements an
interface method it makes a thunk to adjust the 'this' pointer before calling
the actual class method. So when you have an interface A and class C and call a
method f in A that is implemented in C the slot in the vtable for f (which takes
an A) calls the thunk to adjust the A to a C and then the thunk jumps to the
method (which takes a C).

-Ben





More information about the Digitalmars-d-announce mailing list