:
I was wondering if there are any open source compilers out there to
translate the C++/Java/C#-like object model to C. Thanks,
David
Hidden pointers is what OO is all about for the most part.
The following in C++:
class Circle {
public:
double radius;
virtual double GetArea(void)
{
3.14 * radius * radius;
}
};
is implemented as:
typedef struct VTable_Circle {
double (*GetArea)(Circle*);
} VTable_Circle;
typedef struct Circle {
VTable_Circle const *vtable;
double radius;
} Circle;
double GetArea(Circle *const this)
{
return 3.14 * this->radius * this->radius;
}
VTable_Circle vtable_circle = { GetArea };
void ConstructCircle(Circle *const p)
{
p->vtable = vtable_circle;
}