Using C++ compilers for C

This is a discussion on Using C++ compilers for C within the C Programming forums, part of the General Programming Boards category; My old IDE (Quincy) had options for creating/compiling both C and C++ source files, my new IDE (Visual Studio 6) ...

  1. #1
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591

    Question Using C++ compilers for C

    My old IDE (Quincy) had options for creating/compiling both C and C++ source files, my new IDE (Visual Studio 6) only has the one: C++. Now, I know C code is essentially C++ code too and can be compiled in a C++ compiler, but I would think that, if given the option, compiling it in a C-specific compiler might be more appropriate.
    So.. is there any advantage to be gained in using a C-specific compiler for compiling C code over compiling it in a C++ compiler?
    Thanks.

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    Simply put your code between this:
    Code:
    extern "C" {
    
    }

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    Quote Originally Posted by Desolation
    Simply put your code between this:
    Code:
    extern "C" {
    
    }
    extern "C" has nothing to do with C programming or the OP's problem. You might want to look up what that means before suggesting it.

    To the OP: Yes, there are advantages of compiling C in a C compiler over a C++ compiler. C and C++ both conform to different rules and standards that will effect your resulting application if compiled and linked as a different language from the one in which it was written. For instance returns on things like malloc() and the value of NULL is different in C and C++.

    There are many free C compilers that you can and should use to compile your C programs. Try GCC or Dev-C++ if you prefer an IDE.
    Sent from my iPadŽ

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    IIRC extern "C" is for linkage only. It doesn't actually allow you to parse and compile C source AS C.

    Unless your compiler has an option to compile as C then you are kinda suck. Yes you'll be able to get really close but there will always be a few differences you won't be able to get avoid.

  5. #5
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Thanks guys, I didn't feel quite right putting C code through a C++ compiler!
    Dev-C++ looks like a nice full-featured IDE, I'll give it a try, thanks!

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    Most compilers follow the convention

    foo.c would be compiled as C
    foo.cpp would be compiled as C++

    Also, most compilers can be forced into one language or another by various command line switches.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    13
    Totally from Memory

    VS 6.0 command to compile in C is /TC

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    As Salem said, in VS 6.0, just name the file with a .c extention, and it will be compiled as C code, not C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Builder Comparison
    By ryanlcs in forum Tech Board
    Replies: 14
    Last Post: 08-20-2006, 09:56 AM
  2. Is It Possible To Install Multiple Compilers?
    By mishna_toreh in forum C Programming
    Replies: 3
    Last Post: 05-13-2005, 07:32 AM
  3. Compilers for Windows
    By LegendsEnd in forum Windows Programming
    Replies: 2
    Last Post: 03-26-2004, 07:03 AM
  4. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM
  5. Compilers, Compilers, Compilers
    By Stan100 in forum C++ Programming
    Replies: 11
    Last Post: 11-08-2002, 03:21 PM

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