|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
dvanguard@gmail.com wrote:
> 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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Mark Bluemel wrote:
> dvanguard@gmail.com wrote: >> 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. 'cfront' might be what you're looking for, although I guess the generatted code would be pretty illegibel to humans. Bye, Jojo |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Jan 31, 11:32 am, Mark Bluemel <mark_blue...@pobox.com> wrote:
> dvangu...@gmail.com wrote: > > 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. yep cfront did it (the original compiler for AT&T). I think comeau c++ compiler still does that: from C++ sources it generates C code http://www.comeaucomputing.com/. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Jan 31, 8:20am, dvangu...@gmail.com wrote:
> I was wondering if there are any open source compilers out there to > translate the C++/Java/C#-like object model to C. Thanks, Here you go: http://www.softwarepreservation.org/.../release_3.0.3 Don't imagine that reading the C output will be enjoyable. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
:
> 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; } -- Tomás Ó hÉilidhe |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
dvanguard@gmail.com wrote:
>I was wondering if there are any open source compilers out there to >translate the C++/Java/C#-like object model to C. Thanks, Check the Portable Object Compiler for an Objective-C to C translator: http://users.pandora.be/stes/compiler.html Roberto Waltman [ Please reply to the group, return address is invalid ] |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
"Tomás Ó hÉilidhe" <toe@lavabit.com> wrote in message
news:Xns9A36E9FB8AD8toelavabitcom@194.125.133.14.. . > : > >> 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++: > [...] > > 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; > } FWIW, you can use some macros to implement the interface so you don't have to write code like: Circle c; ConstructCircle(&c); c.vtable->GetArea(&c); Something like: #define Circle_GetArea(mp_this) ( \ (mp_this)->vtable->GetArea((mp_this)) \ ) Now you can do: Circle c; ConstructCircle(&c); Circle_GetArea(&c); Also, if you pick some standard function names in the vtable, you could do some abstract interface stuff... Something like: typedef struct VTable_Circle { void (*Object_Destroy) (Circle*); double (*GetArea)(Circle*); } VTable_Circle; #define Object_Destroy(mp_this) ( \ (mp_this)->vtable->Object_Destroy((mp_this)) \ ) and write: Circle c; ConstructCircle(&c); Circle_GetArea(&c); Object_Destroy(&c); The Object_Destroy function will work for any object which follows the "standard" vtable naming convention. Here is a more complete example: http://groups.google.com/group/comp....106926ba5db19f IMHO, it makes things "cleaner"... And in some respects, I like it better than C++... ;^) |
|
![]() |
| Outils de la discussion | |
|
|