Writing C code in VS2005

This is a discussion on Writing C code in VS2005 within the C Programming forums, part of the General Programming Boards category; Hi I have visual studio 2005 and have been writing C code in it. However, I have done this in ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    15

    Writing C code in VS2005

    Hi

    I have visual studio 2005 and have been writing C code in it. However, I have done this in a rather round-about way. I created an empty c++ project, added a .cpp code file, wrote normal C into it and compiled, which works.

    Is there a way to create a C project instead of me having to create a c++ one?

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,758
    I do not think that there is a C project option, but of course you can give your source files a .c extension and change the project settings to have the code compiled as C code (/TC, under Configuration Properties -> C/C++ -> Advanced).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    I do not think that there is a C project option, but of course you can give your source files a .c extension and change the project settings to have the code compiled as C code (/TC, under Configuration Properties -> C/C++ -> Advanced).
    And if the file is already called something .c instead of .cpp, it will automatically choose to compile it as C rather than C++ (Unless you specifically change it with the /TP option of course).

    If the files do not have the right naming convention, I suggest you rename the files rather than using the /TP or /TC option, since anyone else looking at your code would be terribly confused by C code written in a file called .cpp or C++ code in a .c file.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    The third solution, if you really want, is just to let it compile the C code as C++ code.
    Visual C++ doesn't support the C99 standard so pretty much everything in c is available under C++ too.
    And well written C++ code (without using new/delete) is compatible with C, as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Elysia View Post
    And well written C++ code (without using new/delete) is compatible with C, as well.
    I wouldn't really go that far.
    Assuming you limit yourself to the C half of C++ and not use classes or anything, there are still some very minor differences that would stop some C++ code from compiling in a C compiler.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by cpjust View Post
    I wouldn't really go that far.
    Assuming you limit yourself to the C half of C++ and not use classes or anything, there are still some very minor differences that would stop some C++ code from compiling in a C compiler.
    I agree. Most of the differences may be benign, but code that compiles in C++ (without using C++ features) may not compile in a C compiler. And unless it is known that the code will always be used on a system that will have a C++ compiler, it is not a good idea to use a C++ compiler to compile C. There is a risk that some C++ specific features sneak in there that make the code incompatible with standard C.

    If for no other reason than C++ requires casts on malloc() when C doesn't.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    Yes, well, I wouldn't go as far as to recommend it. I'll be happy just to mention it's an option. It has its ups and downs, though.
    But these are basically the 3 choices you have to compile your C code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing Code
    By ILoveVectors in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2005, 12:27 AM
  2. Writing code for a program in C
    By Sure in forum C Programming
    Replies: 7
    Last Post: 06-11-2005, 01:33 PM
  3. professional programmers, do you spend more time writing or modifying code
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 11-25-2002, 09:54 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

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