translating oo features to C

D

dvanguard

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
 
M

Mark Bluemel

I was wondering if there are any open source compilers out there to
translate the C++/Java/C#-like object model to C. Thanks,

An early C++ "compiler" perhaps?

As I understand it, C++ was initially precompiled to C source.
 
J

Joachim Schmitz

Mark said:
An early C++ "compiler" perhaps?

As I understand it, C++ was initially precompiled to C source.
'cfront' might be what you're looking for, although I guess the generatted
code would be pretty illegibel to humans.

Bye, Jojo
 
T

Tomás Ó hÉilidhe

:
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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top