Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if a project is C or C++ in Visual Studio?

How does Visual Studio know if a project is C or C++? Is there any configuration or build parameter that indicates this ?

Does VS use C compiler for C, and C++ compiler for C++ ?

like image 703
onmyway133 Avatar asked Mar 21 '13 13:03

onmyway133


2 Answers

Does VS use C compiler for C, and C++ compiler for C++ ?

No

the cl compiler is smart enough to know(based on file extension) if a file is a .cpp or .cc file - which it considers as C++ file. And the cl compiler will consider a .c file as a C program source file, and compile accordingly. Although it does load a separate dll file for compiling C and C++ file. But this is implementation defined.

However, there is a switch to override the behavior of cl based on file extension.

To compile as C++ source file (even with extension of .c), command would be: cl /TP yourfile.c note however, the file should contain valid C++ code.

And to compile as C source file (with extension of .cpp), command would be: cl /TC yourfile.cpp note however, the file should contain valid C code.

like image 134
Aniket Inge Avatar answered Sep 30 '22 15:09

Aniket Inge


Apart from extension, if you go to File Properties->Advanced, there's a Compile As option, which may be used to explicitly treat the code as C code.

It generates /TP for C++ and /TC for C.

As Joachim noted in comments, though, VC++ isn't exactly the most conforming compiler on the planet, so picking "whatever works" might be actually a reasonable option.

like image 20
Bartek Banachewicz Avatar answered Sep 30 '22 16:09

Bartek Banachewicz