Visual C++ 2008 Question
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 :)
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).
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.
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++.
Originally Posted by Elysia
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.
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.
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.
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.