Thread: Visual C++ 2008 Question

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688

    Visual C++ 2008 Question

    Hey guys

    C++ is the default langauge when you create a project, but is there an option to set it as C?

    You could place .c after the file name but I was wondering is there an acutal option that will compile all code as .c and not .cpp?

    Thanks in advance
    Double Helix STL

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You can set each individual file in the compile options for that file whether you want it to compile as C or C++. The command line option is /TC or /TP (or something like that).

    Obviously, creating the files with the right extension (and renaming them if need be) is the best option, because it can be quite confusing to someone else if they are reading the code and seeing a .cpp file, which is then expected to be compiled as C (or the other way around).

    --
    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.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, project options -> C/C++ -> Advanced. You'll spot it.
    I don't recommend compiling .cpp files as C, or the other way around though. Might confuse people.

    But I don't think you can specify C when you create the project, though.
    Nevertheless, I don't see why you need C. Just do your code in C++/C. Much, much safer.
    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.

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by Elysia View Post
    Nevertheless, I don't see why you need C. Just do your code in C++/C. Much, much safer.
    Some people need to reuse legacy code in new projects. Setting an option is easier than a rewrite to fix incompatabilities between C and C++.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I think it's better to compile that code as C instead and keeping the rest as C++/C. Break it out into a new function, if possible.
    That is what I would do anyway, although no one else is forced to do the same.
    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.

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Thats what the OP is trying to do, get his C code to compile as C code, at least thats how I percieved the isue. He doesnt really specify why he is trying to do it, so it could be anything, even an instructors requirement.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yeah, I already answered that one, but...
    For a new project that uses C, it's better to do C++/C, and if you need to use legacy C code that won't compile as C++, it can be put inside a .c file and possible broken into a function and called from the C++/C code. That's what I was referring to.

    I took is as the OP wants the compile the entire project as C.
    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.

  8. #8
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Yeah, its more difficult when they already have a solution in mind and want help implimenting that solution, when it would be better to discuss the problem so that the best solution could be discussed. My boss does this to me all the time, then wonders why his solution didnt solve the problem, when my assignment wasnt to solve the problem, often I don teven know what the problem is, just teh solution he wants implimented.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C & visual studio 2008
    By Red Maw in forum C Programming
    Replies: 2
    Last Post: 04-02-2009, 09:06 PM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. visual c++ 2008 express
    By manzoor in forum C++ Programming
    Replies: 2
    Last Post: 02-07-2008, 05:31 AM
  4. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  5. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM