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++文件?
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.
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
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.
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。谢谢你！