Translate C++ to C

G

Gancy

Hi all,
Are there any version of g++ that translates C++ to C. or any open
source compiler to do this.

Thanks
Ganesh
 
K

karthik.naig

Hi,
C++ was created because C and other procedure-oriented languages
could not address the complex problems that are present in real life.

So the question of translating C++ code to C is absurd. You have to
rewrite the code completely and that would be no small feat.

Regards,
Karthik.
 
S

Spiro Trikaliotis

Hello,

C++ was created because C and other procedure-oriented languages could
not address the complex problems that are present in real life.

Ah, so C cannot be used to write complex problems of real life? I
believe you should not shout this here in this newsgroup. ;-)
So the question of translating C++ code to C is absurd. You have to
rewrite the code completely and that would be no small feat.

But remember: The first versions of C++ were implemented as a
preprocessor only, which produced a C source which had to be compiled by
a C compiler afterwards. Thus, such beasts do exist (but I do not know
if they exist for recent C++ versions).

Anyway, I do not know if that C code is very human readable afterwards.

Regards,
Spiro.
 
W

Walter Roberson

C++ was created because C and other procedure-oriented languages
could not address the complex problems that are present in real life.
So the question of translating C++ code to C is absurd. You have to
rewrite the code completely and that would be no small feat.

Sorry, Karthik, but your history is not accurate.

C++ *is* a "procedure-oriented language", just with a more
flexible mechanism than for C to decide -which- procedure to use.

If you want a non-procedural language, you will have to look at
programming languages such as PROLOG that specify goals and
leave it up to the language implimenter on how to systematically
approach the goals. Do not confuse "object-oriented" with
non-procedural !!

C++ was not invented because C *could not* be used for certain
problems: C++ was invented because reformulating parts of C made
for a language that some problems easier to express, and made it
easier to write generalized toolkits to encourage software re-use.

The only part of C++ that is noticably difficult to express
in C is "exceptions" -- which were *not* the driving force of
C++ language development [unlike, say, Ada.]


Translating C++ to C is *not* "absurd". The first C++
compilers, designed by the author of C++ himself, was
'cfront', which translated the C++ code into C for
compilation by your nearest handy C compiler. 'cfront'
was managed and distributed by AT&T at the time, and
is still available from Lucent (the vehicle that
AT&T spun a fair bit of their technology off to.)
I found it on lucent's site just yesterday. I happened
to be using an old browser so I couldn't easily check
out the licensing conditions and pricing.
 
S

sgerchick

Gancy said:
Hi all,
Are there any version of g++ that translates C++ to C. or any open
source compiler to do this.

Thanks
Ganesh

On some modern C++ compilers there is an option to generate C code
(like in the cfront days)
 
K

karthik.naig

Walter said:
life.

Sorry, Karthik, but your history is not accurate.

C++ *is* a "procedure-oriented language", just with a more
flexible mechanism than for C to decide -which- procedure to use.

If you want a non-procedural language, you will have to look at
programming languages such as PROLOG that specify goals and
leave it up to the language implimenter on how to systematically
approach the goals. Do not confuse "object-oriented" with
non-procedural !!

C++ was not invented because C *could not* be used for certain
problems: C++ was invented because reformulating parts of C made
for a language that some problems easier to express, and made it
easier to write generalized toolkits to encourage software re-use.

Thanks for the illumination. This is the first time I'm hearing this.
And sorry for the wrong information earlier. Anyway, I'm glad I posted
this to the group.
The only part of C++ that is noticably difficult to express
in C is "exceptions" -- which were *not* the driving force of
C++ language development [unlike, say, Ada.]

What about constructors, virtual base classes, inheritance,
polymorphism etc?
Translating C++ to C is *not* "absurd". The first C++
compilers, designed by the author of C++ himself, was
'cfront', which translated the C++ code into C for
compilation by your nearest handy C compiler. 'cfront'
was managed and distributed by AT&T at the time, and
is still available from Lucent (the vehicle that
AT&T spun a fair bit of their technology off to.)
I found it on lucent's site just yesterday. I happened
to be using an old browser so I couldn't easily check
out the licensing conditions and pricing.
--

So how would you translate a class definition and object construction
into C? Use structures and then malloc? Won't this be a huge task
indeed? I would definitely be interested in learning more about this.
Can you provide some links that would help in understanding the concept
better?

Thanks and Regards,
Karthik.
 
W

Walter Roberson

Walter said:
The only part of C++ that is noticably difficult to express
in C is "exceptions" -- which were *not* the driving force of
C++ language development [unlike, say, Ada.]
What about constructors, virtual base classes, inheritance,
polymorphism etc?

My understanding is that virtual base classes and inheritance
become fixed at compile time -- one can climb the type hierarchy
to figure out what is what, since one has to define a class before
using it in a derived class. I could be wrong, as I have not used
C++ in a few years.

It's been a while since I read The Design And Evolution of C++,
but my -recollection- is that polymorphism came later. In any case,
one can have the overhead structure include a member which indicates
the type, and could if necessary include a pointer to a list of
types. The compiler could build up a type symbol table and then
save space by storing a type number rather than a type name. Or
you could make arrangements based upon pointers into the type tables
of subelements of class hierarchies. Whatever.

So how would you translate a class definition and object construction
into C? Use structures and then malloc?
Sure.

Won't this be a huge task
indeed?

The code wasn't pretty, and it was somewhat verbose in order to
take all the conversions into account, but I'm told that
with a bit of practice one could debug it.
I would definitely be interested in learning more about this.
Can you provide some links that would help in understanding the concept
better?

http://www.lucenttls.com/displayProduct.cfm?prodid=56

http://www.cs.usfca.edu/~parrt/course/652/lectures/language.impl.overview.html
 

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