Which is the best C++ compiler? [closed]

点点圈 提交于 2019-12-20 10:48:11

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


In addition to Bastien Léonard answer: There is one more multi-platform C++ compiler — Comeau. It is the most standards-conformant C++ compiler. Last version has C++0x core language support.




回答5:


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.




回答6:


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.




回答7:


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.




回答8:


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.




回答9:


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> for instructions.

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

[/edit]



来源:https://stackoverflow.com/questions/1114860/which-is-the-best-c-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!