Compiling C++ to C?

This is a discussion on Compiling C++ to C? within the C++ Programming forums, part of the General Programming Boards category; Are there any C++ compilers that generate C code?...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    167

    Compiling C++ to C?

    Are there any C++ compilers that generate C code?
    silk.odyssey

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Compilers don't generate high level code like C or C++. They generate assembly/machine code. Both C++ and C compile to the same stuff, native code I believe it's called.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    Some compiler can generate assembly code and I just thought it would be nice if they produced C code also so that I can understand C++ better
    silk.odyssey

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    You mean convert C++ code to C code? That would be incredibly difficult, especially if your C++ code had classes, multiple inheritance, and stuff like that. I'd say it's not worth your time.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    I thought maybe the converted code would be simplified but i guess that would not be the case
    silk.odyssey

  6. #6
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    sorry to burst anyones bubble here, but the answer to the original question: Are there any C++ compilers that generate C code?

    is YES.

    In fact, when C++ was originally created, ALL C++ compilers generated C code. NONE of them went straight to assembly.

    That was because a solid C++ standard and compiler had not yet been built, so companies built extensions which allowed people to use the C++ language. Then, when they compiled their code, the first thing the compiler would do would be to run it through a preprocessor which would convert all C++ code to C code, and then compile the C code to assembly.

    If you go back far enough you might be able to download one of those original compilers somewhere on the internet.
    My Website

    "Circular logic is good because it is."

  7. #7
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    I've giving up on that. If I find an old compiler it wouldn't compile the code I have anyway
    silk.odyssey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling Issues
    By pc_doctor in forum C Programming
    Replies: 3
    Last Post: 11-30-2007, 10:00 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Problem Compiling
    By Flakster in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 02:09 AM
  4. Compiling
    By Dae in forum C++ Programming
    Replies: 7
    Last Post: 06-15-2005, 02:08 AM
  5. compiling and executing issue with lcc win32
    By GanglyLamb in forum C Programming
    Replies: 10
    Last Post: 12-22-2004, 02:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21