Question

I've always been compiling my C/C++ code with gcc, however I only recently became aware of the fact that it is not the only free compiler.

I've been toying around with switching, as some of these other compilers, particularly clang, seem to show a lot of promise. My criteria for my compiler are compliance with the C99 standard immediately, and more standards as they become more common, as well as its being free and open source, and compiling my code as optimally as possible. Compiling quickly is not so important to me, but is always a good plus. That said, if there are any compilers that seem like they might soon surpass gcc, I would like to know if it is worth switching now for the sake of learning.

I will be using it mainly to compile C++ code, so this takes priority for me over C. I will be building on linux for linux, so a good CLI is a must. I do not mind a certain degree of instability so long as the binaries are of good quality.

Was it helpful?

Solution

There is no optimal compiler for all projects, purposes and expectations.

  • Every project (including compiler projects like gcc or llvm) has slightly different priorities (e.g. support for latest language standards, standard purity vs. performance, compiling performance vs. run-time performance etc.).
  • There are many benchmarks and ways how to compare them. Yet often, if one wins compiling one program (for arbitrary definition of victory), there usually exists other program, where the other compiler wins (for the same definition of victory).
  • The previous point is also valid for the same compiler when used with different optimization options. Some optimizations sometimes (hopefully more often :-) help but sometimes (for other code) they actually hurt performance.
  • The compiler benchmarks are also always criticized due not using the same level of optimizations etc. because always some reader of the comparison article actually expects other aspects to be bench-marked. This is due each compiler has different defaults optimization level, uses different optimizations on different optimization levels, same optimizations are implemented differently in different compilers, and some optimizations are supported only in some compilers at all.
  • The results can also differ on different platforms, or CPU model.
  • Both gcc and llvm are very actively developed, so any comparison between them is already outdated in the time when it is published.

This all also results into that developers are also projecting their personal (dis)liking to one or other compiler, sometimes leading to flame wars. So the only answer you can get is: "It depends."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top