tags:

views:

414

answers:

8

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?

+3  A: 

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.

omgzor
This isn't really a valid argument; MSVC is also tested quite extensively since a lot of Windows software depends on it.
You
@You: The focus in this answer was on multiple architectures... this is definitely a strength of gcc vs MSVS.
jkerian
@jkerian: That is true, but it does not imply that MSVC is "untested". The modified answer is better.
You
MSVC has a test run of several hundred thousand test cases every release: http://blogs.msdn.com/b/vcblog/archive/2010/06/01/how-we-test-the-compiler-backend.aspx
the_mandrill
+1  A: 

MSVC is much better for debugging job. If MSVC could export make files then cross-platform development would be much easier.

rcen
+13  A: 

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.

Klaim
To your point about the standard, MSVC tends to give the programmer the benefit of the doubt a lot more. This isn't necessarily bad or good, it's just important to keep in mind that just because it compiles on MSVC doesn't mean it will compile in GCC. A really good example of this is in template coding and the need, in GCC to preface the template variable with a `typename` eg `template <typename T>` whereas MSVC simply assumes `T` is a typename rather than some other token.
Chris Thompson
@Chris Thompson: The template example is wrong. Since VS6 Microsoft did a great job of improving standard compliance. As for today they are as compliant to C++03 as GCC. Of course both compilers have their own bugs.
ybungalobill
@ybungalobill Ah, they may have fixed it, this example was from a few years ago.
Chris Thompson
@ybungalobill: VS2010 also supports a subset of C++0x just as GCC does. Although they support different subsets. So the MSVC team is on the ball I would say but that might not be as suprising as Herb Sutter is with them. Any input on how the Intel compiler compares to the others?
FuleSnabel
Visual Studio Express is "free" in the sense of "comes with," not in the sense of "free of encumbrance." GCC does not "come with" a debugger, but most systems that have GCC have GDB. This is just a matter of Unix philosophy. You say VSE is a "very powerful debugger" compared to GDB: can you give some reasons?
Joel J. Adamson
@Joel: It doesn't crash? ;) Seriously, both GDB and the Visual Studio debugger are powerful *enough*. The VS one has a much nicer interface though (and yes, I know about the various GDB frontends, most of which introduce *even more* crashes)
jalf
I'm not really sure which compiler implements the "most" of the standard. Both GCC and MSVC are pretty good in that respect, but they also both have areas they don't implement. My gut feeling is that if you were to measure up exactly how much of the standard each compiler implements, GCC would come out ahead, but not by much, and not so much that it really makes a difference.
jalf
"MSVC goes with a free IDE (Visual Studio Express) THAT IS KNOWN to have a really powerful debugger" as in "I didn't try but a lot of people say that so take it with distance".jalf> Yeah not by much and not on the same features than other compilers, AFAIK.
Klaim
With regard to compilation time, gcc is faster, by far. See http://stackoverflow.com/questions/2251212/how-to-improve-visual-c-compilation-times
Didier Trosset
That depends a lot on : 1) the GCC version 2) the project's C++ features usage (i'm thinking about templates for example) By the way, Clang seem to beat GCC by a magnitude. However it generate slower code. Some infos can be found on recent discussions on the boost mailing list : http://article.gmane.org/gmane.comp.lib.boost.user/62107
Klaim
@jalf: Well, if it doesn't crash that's great, but I'll tolerate occasional crashes to preserve my personal freedoms.
Joel J. Adamson
@Joel: sooo you're saying the MSVC compiler took away your freedoms? Good grief, some people need to grow the hell up. If the debugger enslaved you or something, I suggest you take it up with the UN's human rights watch. Otherwise could we pleeeeeease leave the hollow and ridiculous rhetoric at the door? By the way, I'd just like to point out that unlike you, I have the freedom to use *both* debuggers. You, apparently don't. So much for GDB safeguarding you against oppression.
jalf
@jalf: if I chose to use a Microsoft product, it would be me denying myself four basic freedoms. Of course I have the freedom to use it, but when I use it, I sacrifice other freedoms that are more important. I choose not to. My "hollow and ridiculous rhetoric" pointed out the difference between something being "free as in price" and "free as in freedom." That's a big difference that people need to know about.
Joel J. Adamson
+4  A: 

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.

Nemanja Trifunovic
This is my experience too. MSVC generates much faster code, but I wouldn't say it's better just for that.
Matt Joiner
A: 

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.

jkerian
+3  A: 

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.

Jerry Coffin
Wrt requiring "template" - in a sense, that's a test like Acid3. It doesn't test whether the compiler does the right thing in the normal case, but merely whether it does the tight thing when you do not. And the consequences of getting it wrong are fairly trivial.
MSalters
A: 

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.

Nick Oakley
A: 

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

Jonathan Leffler