I often read that the GCC compiler is much better than the Microsoft compiler on various forums and comment thread. This is always because "Micro$oft is evil" and that GCC is open-source. Are there any technical reasons that GCC is better? Are there any scenarios where one would want to use GCC over MS for windows development? Are there any issues with cross-platform development?
As there's such a large code base that depends on C, (and gcc is free) it's one of the first things to be implemented on any new architecture.
GCC is also the most portable C compiler.
From wikipedia:
With GCC, most of the compiler is the same on every platform, so only code which explicitly uses platform-specific features must be rewritten for each system.rewritten for each system.
MSVC is much better for debugging job. If MSVC could export make files then cross-platform development would be much easier.
There are pros and cons with all tools. Those that are the most used are the less problematics so what you need is a list of differences between the two compilers (are they are known to not be harmful). You can find some on stackoverflow or somewhere else.
From what I know :
- GCC is cross-platfom : all unix-like platform have a version, and even others. MSVC is Microsoft-OS targets only;
- GCC is known to implement (a bit) more correctly the C++ standard. It also currently implement more features of the next standard than other compilers;
- MSVC is better on compilation time and generate faster code than GCC (from several discussions on the boost mailing list);
- MSVC goes with a free IDE (Visual Studio Express) that is known to have a really powerful debugger, that makes debugging sessions (70% of programming time) easier. GCC don't realy have an equivalent, althought GDB seems to be something similar (I don't know much about it).
Now there are a lot other differences, but I think those are the main to know to make an idea. If you're targetting cross-platform dev, maybe using GCC will be more helpful, maybe not as MSVC seem better on windows than the GCC port (MinGW).
When there is a blurry line between too widely used tool, it's always because those tools just solve problems in the same domain differently, so just list the differences and make your choice on a project basis.
Disclaimer: I've worked with both compilers and like them both.
Now, technically speaking, the GNU compiler has one big advantage that may or may not be important to you: portability. It is also more "cutting-edge" when it comes to implementing the C++ Standard, but Microsoft's compiler is very good in that area as well. On the other hand, I like Microsoft's way of distributing symbols (pdb files) much better than GNU's, and in my experience VC++ sometimes generates better machine code.
To cut the long story short: both compilers are excellent nowdays and any claim that one is "much better" than the other is unfounded - at least from the technical standpoint.
It sortof depends on what you mean by 'better'. For a moment let's put aside the development environments and surrounding OS/licensing worldviews.
Judging only the compiler itself, gcc tends to be faster to respond to new technical reports and language developments. It also has a bit of an edge when it comes to grafting new tools onto the compiler (simply the nature of open source software).
Execution speed of the resulting binaries is devilishly hard to compare, particularly since you need to understand the compilation flags of both environments very well. The sheer number of bad comparisons out there, from people who should know better is stunning. Such comparisons can also be very dependent on the type of processing that is being done.
For the most part though, this is a "when in Rome..." situation. Use MSVS (possibly express) on windows, use gcc on *nix, use whatever works on embedded targets, and use a decent build system that abstracts most of the issues if you're targeting both.
First let me say that as-asked, this should probably be closed as "not a real question" or something on that order. "Better" is a value judgement, not a fact. Likewise, any answer about why things are the way they are is almost certain to contain more speculation than fact. To avoid problems from those, I'm going to start by stating some assumptions about what "better" means: 1) that it produces more efficient code, or 2) that it conforms more closely with the C++ standard.
As far as conformance goes, I'd say that right now g++ conforms more closely that MSVC does. Especially in terms of conformance, g++ tends to improve fairly incrementally -- i.e., virtually every new version has some minor improvements in conformance, but no one release has really made a huge difference.
MSVC has followed rather the opposite path: the degree to which it conforms stays nearly constant for quite a while, and then a new version is released that makes huge progress. For example, when MSVC 6.0 was new, it was close to cutting edge in terms of conformance (with a standard that wasn't even approved yet at the time). It remained MS' current C++ compiler for a long time. By the time it was replaced with version 7.0, it was well behind the competition, and 7.0 provided only a minor improvement. That, however, was replaced by version 7.1 fairly quickly -- and (despite the "minor" change in version number" was a huge step forward in terms of conformance -- good enough that when it was released, it clearly conformed much more closely with the standard than g++ did at the time.
Since 7.1, MSVC has been back to making only fairly minor improvements -- to the point that I'd say it's behind g++ again. This probably shows up the most in template code, where g++ actually enforces the standard's requirement to use typename
when you want a dependent name to refer to a type rather than a variable. MSVC is a lot more like g++ 3.x in this regard, rarely requiring that you use typename
, even though the standard requires it.
Quality of code is almost impossible to compare: gcc has back ends for a lot of processors, where MSVC really only targets Intel x86/x64 (and compatibles). At least from what I've seen that makes it rather unsurprising that gcc puts more effort into the front-end, doing more work with architecture-independent optimizations where MS seems to concentrate more effort on the back end code generation. That does tend to vary with gcc though: since there are so many back ends, there's quite a bit of variation between them.
As far as speculating about why things are the way they are, I think it primarily comes down to one thing: at Microsoft the single biggest customer for the compiler is Microsoft itself. Its development tends to be driven somewhat more pragmatically -- features are added primarily when/if/because they can see where the feature will benefit their own development. They also have a huge amount of code they need to maintain, so backward compatibility is an equally huge concern for them. Even when they modify the compiler to improve conformance (e.g., changing the scope of variables defined in a for loop) they work much harder at maintaining compatibility with existing code that depends on non-conforming behavior.
For g++, the compiler is much more "independent". There's a much greater likelihood of features being developed simply because somebody finds them interesting, regardless of how little effect an accountant would see on the "bottom line". Although there's certainly development that's supported by various companies, there's also at least the possibility that somebody will sit down and write some code simply because he finds some particular feature interesting.
At work, I'll quite happily use whatever they give me - all the IDEs have got niggles, but it's more about compatibility with the team.
On Windows: MSVC usually works out of the box. You get a ton of SDK stuff and examples and docs along with emulators and debugging. You'll get a Windows app running in no time but won't have much idea what's going on at either the compiler/linker level or at runtime under the hood.
GCC ( MingW ) will need to be installed with something like Codeblocks or DevCPP or another IDE unless you want to get down with makefiles ( not a bad thing ).
** Just writing a Windows app and compiling with GCC doesn't mean you can change a compiler setting and get a Linux App! You'll need something like QtCreator in Trolltech's SDK which is coming along nicely nowadays.
At home, I use GCC because it's free and my cheap notebook doesn't get clogged up with myriad junk that I'll never use.
From my perspective as a predominantly C programmer, the biggest advantage of GCC over MSVC is that GCC supports most of the C99 standard and MSVC does not. The parts of most concern to me are things like designated initializers - used in initializing arrays and structures. Having to maintain code that compiles with both MSVC and GCC means that such constructs can't be used, even though they would be of immense benefit to the applications I work on.
There are other useful features in the C99 standard, but designated initializers would be the one I'd nominate as most useful. Variable length arrays (VLAs); macros with variable argument lists; the predefined identifier __func__
; 64-bit long long
; Unicode character encodings with \uABCD
and \U00123456
; the <inttypes.h>
header; snprintf()
and vsnprintf()
; trivia like trailing commas at the end of enumerations -- all those have their uses too (though some are more useful than others).