#include <stdio.h>
 
struct point;
struct point3d;
struct point_it_vtbl;
 
int point_calc(struct point*);
int point3d_calc(struct point*);
void point_init(struct point*, int, int);
void point3d_init(struct point3d*, int, int, int);
void point_print(struct point*);
void point3d_print(struct point*);
 
 
struct point_it_vtbl {
    int (*calc)(struct point*);
    void (*print)(struct point*);
}
	point_vtbl = { &point_calc, &point_print },
	point3d_vtbl = { &point3d_calc, &point3d_print }
;
 
struct point {
    struct point_it_vtbl* vtbl;
    int x, y;
};
 
struct point3d {
    struct point base;
    int z;
};
 
 
int point_calc(struct point* this) {
    return this->x * this->y;
}
 
int point3d_calc(struct point* this) {
    return point_calc(this) * (*(struct point3d*)this).z;
}
 
void point_print(struct point* this) {
    printf("%i, %i", this->x, this->y);
}
 
void point3d_print(struct point* this) {
    point_print(this);
    printf(", %i", (*(struct point3d*)this).z);
}
 
void test(struct point* p) {
    p->vtbl->print(p);
}

int main(void) {
    struct point3d t = { { &point3d_vtbl, 6, 3 } , 9 };
    test((struct point*)&t);
    printf(" %i", t.base.vtbl->calc(&t.base));
    return 0;
}