On Saturday, 1 May 2021 at 15:52:52 UTC, Mike Parker wrote:
No instance is being created by the cast. The instance already
exists. The cast just allows you to treat the pointer to the
instance as a specific type. It’s no different than casting
from C to A really. You just have the void* as an intermediary.
Yes, I know. In fact, this was a stupid question. Not sure what I
was thinking off. I sometimes mix up languages in my head and
came to weird conclusions :P
On Saturday, 1 May 2021 at 16:06:05 UTC, Steven Schveighoffer
wrote:
An interface cast involves a thunk (constant pointer
adjustment) to get to the interface/object. The reason is
because a class with interfaces stores interface vtable
pointers inside the object, and your interface reference points
at that. You can see when you cast between Object (concrete)
type and Interface type, the pointer value changes.
So this will not work. It *does* work for base classes, because
the class vtable pointer is stored at same point, and casting
around class references does not involve a thunk.
This was helpful to understand the ABI chapter better.
Thanks, guys!