在Visual Studio 2010中编译“C”文件时,它是作为c++文件编译的吗?

[英]When one compiles a `C` file in Visual Studio 2010, is it compiled as a C++ file?

C and C++ being different languages, and still I can compile them in Visual Studio 2010 under a C++ project. Why is that? Does the compiler interprets the C file as C++ one instead?

C和c++是不同的语言,我仍然可以在Visual Studio 2010中根据c++项目编译它们。这是为什么呢?编译器是否将C文件解释为c++文件?

4 个解决方案



No, it is compiled as C code.


A C++ project in Visual Studio can contain C++ and C code. The cl compiler recognizes the file extension and compiles it accordingly.

Visual Studio中的c++项目可以包含c++和C代码。cl编译器识别文件扩展名并相应地编译它。

Files ending with .c are compiled as C code. Files ending with .cpp or .cxx are compiled as C++. This can be changed as documented here

以. C结尾的文件被编译为C代码。以.cpp或.cxx结尾的文件被编译为c++。这可以在这里进行修改



Yes it is compiled as C++ file, unless the source file has a ".C" extension


With a few exceptions, C syntax is also valid C++ syntax, so C source code will be often compiled successfully by a C++ compiler.




C is not C++, but the two languages are designed in such a way as to maintain compatibility.


There is a certain common subset that allows one to write .h files which can be included in both C and C++ compilation unit; that is dependent on the language standards.


What's more important, although the standards don't stipulate it, they silently presume that on a given machine the two languages will share a so-called ABI - Application Binary Interface. That allows for calls to be done from one language into another.

更重要的是,尽管标准没有规定,但他们默认在给定的机器上,两种语言将共享所谓的ABI -应用程序二进制接口。这允许从一种语言调用另一种语言。

Unlike languages like C#, Java, or VB.Net, which require all the files of a project to be compiled as a batch, C and C++ are based on the idea of individual compilation units. Therefore it is possible to include files of different types (C, C++, Asm) into a single project.


One can, however, look at it under another angle. I have a C# project where some C# sources are generated by T4. I can regard it as a project where the resulting assembly is made from C# files but the C# files themselves may be obtained by some preparatory steps such as T4 conversion.


In the same way, you can regard a C++ project as a project where the resulting assembly is made from object files, but the object files may be obtained by some preparatory steps such as compilation of C or C++ compilation units. And mind, you can include ready object files into your project as well (typically, in batches called libraries).




no it is not compiled as c++, coz visual studio have support both c and c++ at a time.. if ur compile c program it is compiled as c only ... if u want to compile both in a single program you just add the header file of c and c++. (i.e) #include #include ,if u use both header you can compile both program at a time and also use printf scanf in c++ and u can use cin and cout in c programming.. thank you!

不,它不是编译为c++的,因为visual studio同时支持c和c++。如果你编译c程序,它只编译成c…如果你想在一个程序中编译这两个文件,你只需添加c和c++的头文件。(例如)#include #include,如果您同时使用两个header,您可以编译两个程序,也可以在c++中使用printf scanf,在c编程中使用cin和cout。谢谢你!




C文件无法在c ++ Visual Studio中编译 - C file cannot be compiled in c++ Visual Studio 动态链接库在编译时不会生成.lib文件(Visual Studio c++ Express) - Dynamic link library does not generate a .lib file when compiled (Visual Studio C++ Express) C:在Visual Studio和Eclipse+MinGW中预编译头文件。 - C : Pre-compiled header file in Visual Studio and Eclipse+MinGW 我可以在Visual Studio 2008中使用Visual Studio 6编译的C ++静态库吗? - Can I use a Visual Studio 6 compiled C++ static library in Visual Studio 2008? 如何在Visual Studio 2010中查看C ++函数的已编译机器代码或字节代码? - How do I view the compiled machine code or byte code for a C++ function in Visual Studio 2010? 在Visual Studio C ++中打印每个文件的编译时间 - print compilation time of each file in visual studio C++ 无法在Visual Studio c++ 2010中找到或打开PDB文件 - Cannot find or open the PDB file in Visual Studio C++ 2010 如何在Visual Studio IDE(2008)中打开多CPU /核心C ++编译? - How do I turn on multi-CPU/Core C++ compiles in the Visual Studio IDE (2008)? 为什么致命错误“LNK1104:不能打开文件”C:\程序。当我在Visual Studio中编译c++项目时发生了什么? - Why does fatal error “LNK1104: cannot open file 'C:\Program.obj'” occur when I compile a C++ project in Visual Studio? 在GCC中编译C ++文件时出错 - Error When Compiling C++ File In GCC
粤ICP备14056181号  © 2014-2020 ITdaan.com