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++ ?
Does VS use C compiler for C, and C++ compiler for C++ ?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With