PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > translating oo features to C
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
translating oo features to C

Réponse
 
LinkBack Outils de la discussion
Vieux 31/01/2008, 16h20   #1
dvanguard@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut translating oo features to C

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
  Réponse avec citation
Vieux 31/01/2008, 16h32   #2
Mark Bluemel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: translating oo features to C

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.
  Réponse avec citation
Vieux 31/01/2008, 16h42   #3
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: translating oo features to C

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


  Réponse avec citation
Vieux 31/01/2008, 16h44   #4
ppi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: translating oo features to C

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/.
  Réponse avec citation
Vieux 31/01/2008, 20h16   #5
user923005
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: translating oo features to C

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.
  Réponse avec citation
Vieux 31/01/2008, 23h00   #6
Tomás Ó hÉilidhe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: translating oo features to C

:

> 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
  Réponse avec citation
Vieux 31/01/2008, 23h19   #7
Roberto Waltman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: translating oo features to C

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 ]
  Réponse avec citation
Vieux 15/04/2008, 00h05   #8
Chris Thomasson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: translating oo features to C

"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++...



;^)




  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h14.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,19153 seconds with 16 queries