By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Translate C++ to C

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

Thanks
Ganesh

Nov 14 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.

Nov 14 '05 #2

P: n/a
Hello,

ka**********@gmail.com <ka**********@gmail.com> wrote:
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.

--
Spiro R. Trikaliotis http://cbm4win.sf.net/
http://www.trikaliotis.net/ http://www.viceteam.org/
Nov 14 '05 #3

P: n/a
In article <11*********************@l41g2000cwc.googlegroups. com>,
ka**********@gmail.com <ka**********@gmail.com> wrote:
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.
--
"I want to make sure [a user] can't get through ... an online
experience without hitting a Microsoft ad"
-- Steve Ballmer [Microsoft Chief Executive]
Nov 14 '05 #4

P: n/a

Gancy wrote:
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)

Nov 14 '05 #5

P: n/a
In article <11**********************@l41g2000cwc.googlegroups .com>,
ka**********@gmail.com <ka**********@gmail.com> wrote:
Walter Roberson wrote:
In article <11*********************@l41g2000cwc.googlegroups. com>, 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.

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.

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/cours....overview.html
--
Look out, there are llamas!
Nov 14 '05 #6

P: n/a
Gancy wrote:
Hi all,
Are there any version of g++ that translates C++ to C. or any open
source compiler to do this.


It's not open-source, but Comeau C++ (http://www.comeaucomputing.com/)
works by translating C++ to a platform-specific version of C,
customised for the native C compiler on the system.

--
Simon.
Nov 14 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.