C++ compiler differences [closed]
What's the difference on the VC++.net complier (cl.exe /EHsc) and the GCC compiler, compiling, let's say this program:
#include <iostream>
using namespace std;
int main(){
unsigned int test;
cin >> test;
cout << test;
return 0;
}
I know that the vc++ compiler compiles to an exe, and gcc is compiling to the linux executable, and that's about it. but what's the real diff开发者_Python百科erence?
Edit: I thinking about the difference down to a lower level. Let me make this a little more clear. What's the difference between the same program compiled in 2 different C++ compiler on the same platform (win or linux doesn't matter).
GCC means the GNU Compiler Collection, it is the front end for a collection of compilers and linkers. When compiling C++ it will usually call g++.
As for g++ vs VC++, they are completely different compilers so there are a ton of differences.
For example they will optimize code in different ways, they may have minor syntactical differences based on not following the standard correctly, different libraries, different headers, different implementations, etc...
g++ can be used to compile projects on various different platforms, whereas VC++ is meant to only compile programs for the Windows platform.
I think, different runtime libraries.
G++ cannot compile .net code (since you mentioned VC++.net).
They are completely different since they are develop by different groups with different philosophies.
The differences between compilers are too numerous to comprehensively write in a SO answer, but here's a few:
I assume you're comparing msvc to mingw32 gcc (which can both produce a win32 executable). msvc has different linker options (MT, MD, ML, LD), which link the executable to shared/static and threaded/unthreaded versions of the runtime, including the stdc++ runtime. MinGW (gcc) links to it's own runtime libgcc* either statically or dynamically and to it's libstdc++. MinGW will also link to Windows' msvcrt.dll, and the functions therein, but needs to provide some more statically linked in functionality, resulting in a bit bigger binary. If you're comparing linux gcc to windows msvc, read up on PE and ELF file formats.
Optimization routines are completely different. Read about those in the docs
backend tools are completely different; MSVC uses (among others masm, link, cl) and gcc uses stuff like gcc, g++, cc1, cc1plus (and binutils).
Exception handling: MSVC is the creator of the types of exception handling, so it naturally has the "best" way of dealing with them. GCC/MinGW is catching up, and hopefully release 4.6 will have Structured Exception Handling (Work in progress).
There's more, lots more, but this is all I can think of right now.
GCC will compile and link source code into the ELFformat and a bunch of others (see the comments to my answer), while VC++ will compile and link in the PE format.
** Edit my mistake, GCC will also compile under the PE format for windows. I forgot about that
You can see exactly what the compiler produces by looking at the assembler it generates.
Compile with /FAs on VC++ or gcc -S
精彩评论