在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 个解决方案

#1


6  

No, it is compiled as C code.

不,它是用C代码编译的。

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++。这可以在这里进行修改

#2


3  

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

是的,它被编译为c++文件,除非源文件有一个“”。C”扩展

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语法也是有效的c++语法,因此c++编译器常常可以成功地编译C源代码。

#3


3  

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

C不是c++,但是这两种语言的设计都是为了保持兼容性。

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.

有一个通用的子集允许你写。h文件,可以包含在C和c++编译单元中;这取决于语言标准。

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.

不像c#、Java或VB那样的语言。Net要求将项目的所有文件以批处理形式编译,C和c++基于单个编译单元的思想。因此,可以将不同类型的文件(C、c++、Asm)包含到一个项目中。

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.

然而,人们可以从另一个角度来看待它。我有一个c#项目,其中一些c#源由T4生成。我可以把它看作一个项目,在这个项目中,生成的程序集是由c#文件组成的,但是c#文件本身可能是通过一些准备步骤(如T4转换)获得的。

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

同样,您可以将c++项目视为一个项目,在这个项目中,生成的程序集由对象文件构成,但是对象文件可以通过一些准备步骤获得,例如编译C或c++编译单元。注意,您还可以将准备好的对象文件包含到项目中(通常是以称为库的批次)。

#4


0  

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。谢谢你!

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2014/03/13/4cb074739354c04bdf8114e16f57a00c.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告