Thread: how to execute a c++ prog in a c compiler

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    8

    Talking how to execute a c++ prog in a c compiler

    hi ppl ,,,

    i am having a doubt is there a way that my c++ program could be executed in a c compiler,,,

    thought of asking thats wy

    if u know pls let me know k...

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    program is executed by the OS...
    it is compiled by the compiler.
    What C-compiler you are talking about?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    42

    If that's not the answer you were looking for, you'll have to re-phrase the question.

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    8

    Question

    Quote Originally Posted by vart
    program is executed by the OS...
    it is compiled by the compiler.
    What C-compiler you are talking about?

    i mean there will be some c++ statements which is not present in c... is it possible to make those also execute ????

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    if you succeded in compiling the code, all statements will be executed.
    But I don't understand why do you want a mix?

    Make 2 file, one containing only C code, one - only C++, compile them with the corresponding compiler, then link together
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    8

    how ????

    hi thanks for replyng

    i dont n=know how to link two files,.,,

    i am new to this prog biz,,, can u help me out??

    what are the two files i need to link togethere and what are those files (exe) or anything ?/

  7. #7
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    what compiler?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  8. #8
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    If you are using a fully compliant C compiler ie: all your file names end in .c, it will not understand C++ code. But you can compile C code using a C++ compiler as it has backward compatability with C.

    To my knowledge there is no possible way to force a C compiler to fully execute C++ code.
    Although Im sure Il be corrected on this by Vart!
    Double Helix STL

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Probably not, swgh. Although C and C++ are very similar, still asking a C compiler to compile C++-specific code is, in the end, like asking a Fortran compiler to compile Haskell: completely absurd.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by CornedBee
    Probably not, swgh. Although C and C++ are very similar, still asking a C compiler to compile C++-specific code is, in the end, like asking a Fortran compiler to compile Haskell: completely absurd.
    yes and no...
    Due to OPs lack of exact terming, he can talk for example about VC++...

    The IDE is using by default C-compiler for c-files and C++ compiler for cpp files... And there is a way to change the default behavior. So the c-file will be compiled by the c++ compiler
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  11. #11
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    take this as a rule :
    Any C++ compiler can compile both C++ and C codes

    Any C compiler can only compile C code
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    No, don't. C++ is not a perfect superset of C, and thus not all C programs are valid C++ programs.

    Just compile C code with a C compiler and C++ code with a C++ compiler. Any C++ compiler I've ever seen comes with a C compiler too. (They tend to share a lot of code, too.)
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  13. #13
    Insane Game Developer Nodtveidt's Avatar
    Join Date
    Nov 2006
    Location
    Isabela, PR
    Posts
    105
    It's relatively safe to assume that a modern C++ compiler will be able to handle a .c sourcecode fine though. There are probably exceptions (MSVC6 comes to mind...) but for the most part, it's pretty much the way it is.
    Last edited by Nodtveidt; 01-12-2007 at 07:55 PM.
    Code:
    cout << "Language comparisons are dumb";
    echo("Language comparisons are dumb");
    PRINT "Language comparisons are dumb"
    alert ("Language comparisons are dumb")

  14. #14
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Are the C libraries (e.g stdio.h) that are available to C++ compilers up to the C99 standard, or are they just tools of the C++ified libraries (e.g cstdio) and thus possibly diverged from C? I think that that question is integral to this subject.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  15. #15
    Insane Game Developer Nodtveidt's Avatar
    Join Date
    Nov 2006
    Location
    Isabela, PR
    Posts
    105
    Probably depends on the compiler...I've never had any problems using Intel's or Borland's C++ compilers to compile C code, and obviously gcc doesn't have any problems. MSVC6 requires some occasional project tweaking to compile correctly though, but I don't specifically know about later MSVC builds (they're probably alright since Microsoft suddenly got anal about standards compliance).
    Code:
    cout << "Language comparisons are dumb";
    echo("Language comparisons are dumb");
    PRINT "Language comparisons are dumb"
    alert ("Language comparisons are dumb")

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 09-16-2006, 01:18 PM
  2. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  3. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  4. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  5. Help With finding a compiler
    By macman in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-15-2005, 08:15 AM