Translate C++ to C

Discussion in 'C Programming' started by Gancy, Mar 30, 2005.

  1. Gancy

    Gancy Guest

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

    Thanks
    Ganesh
     
    Gancy, Mar 30, 2005
    #1
    1. Advertising

  2. Gancy

    Guest

    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.
     
    , Mar 31, 2005
    #2
    1. Advertising

  3. Hello,

    <> 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/
     
    Spiro Trikaliotis, Mar 31, 2005
    #3
  4. In article <>,
    <> 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]
     
    Walter Roberson, Mar 31, 2005
    #4
  5. Gancy

    Guest

    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)
     
    , Apr 1, 2005
    #5
  6. Gancy

    Guest

    Walter Roberson wrote:
    > In article <>,
    > <> 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.
    >


    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.
     
    , Apr 15, 2005
    #6
  7. In article <>,
    <> wrote:
    >Walter Roberson wrote:
    >> In article <>,


    >> 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/course/652/lectures/language.impl.overview.html
    --
    Look out, there are llamas!
     
    Walter Roberson, Apr 16, 2005
    #7
  8. Gancy

    Simon Biber Guest

    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.
     
    Simon Biber, May 19, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sridhar Hegde
    Replies:
    2
    Views:
    2,534
    Ajeetha Kumari
    Sep 13, 2004
  2. Rakesh Sharma
    Replies:
    2
    Views:
    2,935
    Thomas Rudloff
    Oct 22, 2004
  3. Nisheeth

    post translate simulation

    Nisheeth, Apr 29, 2005, in forum: VHDL
    Replies:
    2
    Views:
    858
    Mike Treseler
    Apr 29, 2005
  4. Replies:
    3
    Views:
    619
    Bert Cuzeau
    Jun 22, 2005
  5. Replies:
    1
    Views:
    596
Loading...

Share This Page