views:

2386

answers:

9

Can a C++ compiler produce a not so good binary? You can think here of the output's robustness and performance. Is there such a thing as the "best" C++ compiler to use? If not, what are the strong points, and of course, the not-so-strong (known Bugs and Issues) points, of the well-known compilers (g++, Intel C++ Compiler, Visual C++, etc.).

Are there documented cases when a compiler produced incorrect output which resulted in a failure of mission-critical software?

A: 

I found problems using Cygwin, such code that doesn't compile but generates a segmentation fault inside the compiler. The same code works with MinGW.

[edit] Here is the compiler report:

lista.h: In constructor `Lista<Dado>::Lista() [with Dado = int]':
principal.cpp:15:   instantiated from here
lista.h:13: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://cygwin.com/problems.html&gt; for instructions.

I don't have the source code that generated the error anymore, so I can't submit a report.

[/edit]

GogaRieger
Let's suppose that Cygwin actually succeeds in compiling a binary. Can I use that, let's say, as part of a commercial airplane system, or should I doubt the reliability of the compilation.
cmdev
cygwin is not a compiler, cygwin can come with a compiler (gcc/g++) and gcc is a very mature compiler which is used in high quality products. Where I work we use gcc to compile safety critical systems
hhafez
'Cygwin' isn't going to compile anything...
wkf
I'd question the reliability of anything that is compiled with a piece of software that is actually NOT a compiler (Cygwin) and if the compiler (running in Cygwin) really throws a segmentation fault when compiling my code...I wouldnt trust that version of the compiler either and be nice and file a bug report.
cschol
or maybe my code is broken? Don't forget some compilers are more "leniant" than others. For example, I've ported some code from solaris/alhpa (using some proprietary cc) to -> linux 386 (gcc). On the solaris, the cc would hide some bugs by initing un-initialised variables to 0, on gcc, the compiler didn't do that and we started getting segmentation faults. At the end of the day the problem was a coding problem, but one compiler hid it while the other exposed it. I personally preferred what gcc did, exposing the bug so we can fix it!
hhafez
Cygwin is a sort of a distribution of Unix software, so it makes sense to talk anout "cygwin c++". Did you try to submit a bug report to Cygwin mailing list? I did have problems with Cygwin 1.5.x and the guys there were quite helpful. Cygwin 1.7 is now in beta and works quite nicely (I am using it for development both at home and at work), possibly the bug has been fixed in the latest version (the stable distribution is quite old now).
quant_dev
@hhafez: there is a huge difference between a segfault in the compiled code and an internal compiler error; the latter is *always* a bug.
quant_dev
PS. I don't know why people downvote this answer, it is on-topic as far as I can tell.
quant_dev
Nope - question was about the quality of the code generated. In this case, the compiler didn't generate code and emitted an error message. The standard even says it has to do that, if the input is malformed. So this is irrelevant to the topic at hand
MSalters
+3  A: 

First of all which platform you are using usually dictates which compilers to use.

Secondly, your question on robustness and performance. I am not sure what you mean by robustness. but if you mean correctness of the compiled binaries, I'd have to say as long as you are using a stable version of any of the compilers you mentioned you are not going to run into "robustness" problems. These compilers are all very mature and have been used in countless real life projects. So I would not worry about robustness at all.

Regarding performance, That is a tough one to answer because each compiler has different optimisation techniques which could theoretically yield different performance. I hope there is someone more knowledgable than me that can tell you about this.

In reality, given that the compilers that you mentioned are all high quality and mature compilers, the questions that you should be asking, are not which compiler is more robust, but:

  • Which is the compiler that supports my target platform
  • Which is the compiler that works well with my development environment and tools?
  • Which compiler is my development team and integrators most familiar with.

The question of optimisation techniques is an open question however, and it is a non trivial question at that. I hope some could shed some light on it.

hhafez
Was just about to post something similar. For most people it probably won't make a lot of difference.
Nick
You're right about the "correctness" part.
cmdev
So what is your remaining question?
hhafez
+1  A: 

What is the platform you are using? For instance, Visual C++ will not be of use to you on Linux.

Actually, the three you mention are the three I'd have picked, for these reasons.

gcc/g++: open source, proven, refined by years of collaborative experience on many Linux and UNIX systems. The not-so-strong point is merely that it is a stand-alone command-line tool. You can make, or possibly find, your own IDE-style environment but it doesn't "ship" that way, so to speak.

Visual C++: well supported by Microsoft, loads of code samples and documentation (MSDN), naturally hooks into the Windows APIs. The not-so-strong point is that it's not especially, well, "visual." If you're used to Visual Basic (say) you'll find Visual C++ doesn't work the same way at all.

Intel C++ compiler: alas, I have no experience with Intel's compiler but I am lead to believe it supports parallelism and has high-precision numeric libraries.

Another maybe worth mentioning is Borland's C++Builder. It gets a plus for being a rapid application development environment with a wealth of add-on controls via compatibility with Delphi's VCL, but conversely code developed in C++Builder is not easily portable to other C++ compilers.

DavidMWilliams
Are you talking about IDEs or compilers?
Janusz
what do you mea, it's not visual? You are compiling C/C++. How can someone compiling C/C++ expect his code to work like visual basic? What does the compiler have to do with it?
hhafez
Ahh, good distinction. Still, a good IDE enhances the development process, but true, the question was about the quality of the compiled output.
DavidMWilliams
But still a good IDE, will let you chose the compiler to use in the back end ;) and the question is about compilers
hhafez
+12  A: 

G++ seems to be the most popular. It's free, portable and quite good. The Windows port (MinGW) was really dated the last time I used it (maybe one year ago).

The Intel C++ compiler is considered as the one which generates the fastest code (however it's known that it generates bad SIMD code for AMD processors). You can use it freely on GNU/Linux under quite restrictive conditions.
I've used it for some time and I liked the fact that it emits clever warnings which others don't.

VC++ is often regarded as the best C++ IDE, and from what I hear the compiler is quite good too. It's free (as in free beer), and only available on Windows of course.
If you are interested in Windows programming I would suggest this compiler, because it's always up-to-date and provides more advanced features for this purpose.

I would suggest VC++ on Windows, G++ for other OSes. Try the free version of I++ yourself, to see if it's worth the money.


Are there documented cases when a compiler produced incorrect output which resulted in a failure of mission-critical software?

Yes, probably, but I'd say that most of the time it's probably the programmer's fault. For example, if someone doesn't know how floating-point arithmetic works, it's easy to write unreliable code. A good programmer must also know what is guaranteed to work by the C++ standard and what isn't. She should also know what are the limits of the compiler, e.g. how well it implements the standard and how aggressively it optimizes.

Bastien Léonard
The TDM version of MinGW is at version 4.4.0. You can get it from http://tdragon.net/recentgcc/
anon
@Neil: as of 2009-06-23, MinGW gcc-4.4.0 is officially out: http://mingw.org/aggregator/sources/1
Christoph
+1 for clever warnings and errors of the intel compiler. Those are issued from the front-end developed by EDG and licensed to Intel.The Intel compiler comes with an installer, unlike gcc 4.4, which was very painful for me to get installed. So it's pretty easy to try out the Intel compiler.
Drew Hoskins
Actually not so much as bad SIMD for AMD, but more like an cpuid check, against AuthenticAMD, and call the SIMD code incompatible. I don't have the URL anymore, but basically someone found the generated code, removed the badge check, and the SIMD one runs comparably fast as the Intel.
Calyth
MSVS does have good hooks to intercept exceptions and such, so it makes your life a LOT easier. Typically, you've got an exception, and you're trying to find multiple lines that could throw a similar exception. MSVS at debug mode will intercept caught and uncaught exceptions, and breaks at the line that threw the exception.
Calyth
+2  A: 

Since you mention "as part of a commercial airplane system" in a comment, it may be worthwhile looking at the compilers provided by companies that actually maintain certification in that space, or other safety-critical product spaces. Green Hills Software is one. Wind River is another.

Novelocrat
A: 

If you're talking about high performance of the output code in the High Performance Computing sense, you may also be interested in Portland Group's compilers and IBM's XL compilers.

Novelocrat
+1  A: 

The point of an optimizing compiler is that it should generate an optimized program that is functionally equivalent to the original. Functional equivalent has to do with observable effects, of course; the state would naturally not be the same. Any compiler that can generate an incorrect translation is bad, in my opinion, although I suppose that you could relax certain issues in different situations. One advantage of a mainstream compiler is that bugs are fixed faster.

As for performance, compilers generally do two types of optimizations: platform-independent optimizations (at the source level/syntax tree/intermediate representation), and platform-specific ones.

I would guess that the best platform-independent optimizations are probably in various academic modifications of existing compilers (but probably a different optimization and each). These optimizations are eventually recognized and eventually trickle into the mainstream.

As for platform-specific optimizations, I think that companies making these platforms often have the best optimizations (e.g., the internal Intel compilers), but they are not yet integrated into general-availability compilers, and eventually trickle down as well.

Uri
+2  A: 
Kirill V. Lyadvinsky
A: 

http://www.compilers.net/Dir/Free/Compilers/CCpp.htm

Microsoft has a good free compiler, but if you're working on unix or mac that will do you little good.

Borland has a good free compiler as well.

I have tried out several free compilers and feel most comfortable with the Dev-C++. The total package is relatively small in size and comes in windows and linux flavors. For me it is perfect to test out the limits of the C++ language. It compiles fast and makes experimentation easy.

I recommend you this software called Digital Mars C/C++ Compiler,and you can get it from http://www.brothersoft.com/digital-mars-… it is a free C/C++ compiler for the for Win32, Win16, DOS32 and DOS environment.

joe
Dev-C++ isn't a compiler, it's an IDE. It ships with MinGW.
Novelocrat