tags:

views:

123

answers:

6

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 difference?

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

A: 

G++ cannot compile .net code (since you mentioned VC++.net).

They are completely different since they are develop by different groups with different philosophies.

karlphillip
gcc.exe will, if you either let it detect the language or tell it to compile c++, in which case it acts as a frontend to g++.exe.
rubenvb
GCC is *not* a C compiler, it's the entire GNU compiler collection.
casablanca
+7  A: 

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.

Brian R. Bondy
A: 

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

GWW
Not necessarily. GCC is available for the Windows platform too, where it will link programs into an EXE.
casablanca
Untrue: gcc can also produce PE files (*-*-mingw* targets)
rubenvb
This is not entirely true. GCC will compile to whatever format is supported natively on its target platform. GCC configured for a Win32 target will use the PE format (whether it uses Cygwin or MinGW runtimes). GCC configured for MS-DOS or certain Unix platforms will produce a COFF format. Really, it can produce anything binutils' `ld` was compiled for.
greyfade
+1  A: 

I think, different runtime libraries.

Boris
A: 

The differences between compilers are too numerous to comprehensively write in a SO answer, but here's a few:

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

  2. Optimization routines are completely different. Read about those in the docs

  3. backend tools are completely different; MSVC uses (among others masm, link, cl) and gcc uses stuff like gcc, g++, cc1, cc1plus (and binutils).

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

rubenvb
A: 

You can see exactly what the compiler produces by looking at the assembler it generates.
Compile with /FAs on VC++ or gcc -S

Martin Beckett