On 03/04/19 10:53, Markus Armbruster wrote:
> Why (1) our interfaces can't have state:
>
> Since interfaces are abstract, there's no such thing as an interface
> instance.
Well, there is. Since all class instances are Objects, and interfaces
are applied to classes, interface instances must be Object. In fact,
INTERFACE_CHECK() expects that to be the case, since it needs to go
spelunking into the class. However, it is an implementation detail as
far as the interface _user_ is concerned.
> When @obj points to an instance of MyFrob, then we can safely cast it to
> any supertype of MyFrob.
>
> MyIface is not a supertype of MyFrob, it's an interface. WTF?
>
> Turns out we only ever define MyIface in one of two ways:
>
> typedef struct MyIface MyIface; // incomplete
>
> typedef struct MyIface { // fake subtype of Object
> Object parent;
> } MyIface;
>
> If we somehow know that only subtypes of SuperFrob have interface
> MyIface, then we can exploit that and safely cast to SuperFrob * or any
> of its supertypes.
I'm not sure we want to know that. That said, the incomplete type is
much nicer. Anybody wants to add a BiteSizedTask.
Paolo