Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I haven't been following C much in recent years, though I knew that Apple had switched.

Someone want to give (or link to) a brief rundown of the advantages/disadvantages?



There is a little bit on the Clang site:

http://clang.llvm.org/comparison.html#gcc

Outside the license, the main benefit seems to be that in Clang the different stages are less intertwined than GCC. This is supposed to make developing Clang easier (since you don't have to understand so much), allowing optimizations to be tested and added easier.

On the user side, Clang is well known for providing much better error messages. Some error messages will even suggest possible fixes (you might get something like "Can't assign a pointer to a something, did you mean *pointer?").

The GCC guys have been improving their compiler for a long time, and over the last few years they have been working hard to make GCC easier to work on and optimize. I believe that GCC is usually faster or the binaries are smaller by a few percent, but it's not generally a drastic difference.


GCC speedup is actually quite substantial in math/numerical code (which, in turn, is not as fast as Intel's ICC). Moreover, GCC supports OpenMP, whereas Clang does not. This alone make building several scientific software packages not possible with Clang.

It's important to note though that it has only been recently (starting with GCC 4.4) that I've started to see some _improvement_ over previous GCC versions. GCC 3.x was known to be bloated, buggy and emit poor code for almost every architecture. Open64 was superior in _all_ regargs up to GCC 4.2/4.3 in my opinion.

Clearly, the whole project greatly benefited from Clang's competition.


Agreed. Competition is GREAT, and seeing these two excellent open source compiler offerings engaging in friendly competition means we as end users all benefit, no matter which solution we prefer (or use both, as I assume I'm not the only one doing).


Starting with gcc 4.7 and 4.8 the error message for C++ are also improved [1] and start to get close to clang. The competitions seems to be good for gcc and I like to have the choice between two compilers.

[1] : http://gcc.gnu.org/wiki/ClangDiagnosticsComparison


> On the user side, Clang is well known for providing much better error messages. Some error messages will even suggest possible fixes (you might get something like "Can't assign a pointer to a something, did you mean pointer?").*

Here [0] is an example of Xcode leveraging clang to provide valuable feedback. The second picture speaks volumes.

[0] http://www.macfanatic.net/blog/2009/08/28/xcode-3-2-static-a...


While we're on the subject of static analysis and valuable feedback, you should take a look at PVS-Studio, which is pretty neat as well, and is comparable to what clang can do (as far as I can tell from their blog posts).


From everything I've heard pvs-studio is great, but it only runs within Visual Studio. Would love to have an os x or linux version of it some day.


On error report: I wrote some programs in C that heavily reply on huge macros to mimic template in C++. The gcc error report is completely useless as it points to the line with the entire function expanded to a single line. Clang is much more clever.


Yes

I'm not sure how it works in Clang, but of course, GCC doesn't "see" macros, this is seen by the CPP (C pre processor) and GCC operates in C code only

There's a flag (-E) that makes GCC output the preprocessed code and stop


I do not know how clang achieves that, either. BTW, with gcc, I usually do something like this: "gcc -E prog.c | grep -v ^# | indent > prog-fmt.c" This is quite clumsy, though.


Pros:

Faster compile times.

Better error messages.

BSD license.(More in line with their project not a judgement on my part.)

Designed to make use in tools easier.

Cons:

Code produced isn't as fast, but not much slower.


I thought Firefox was seeing speedups from using Clang generated code? I guess I don't know the average case of course, but I'm curious to hear more about this, my Clang/LLVM-fu is weak


Well you are likely thinking of Raphael Espindola's tests of using Clang to build Firefox, and those tests showed that Clang/LLVM was better in some instances but overall GCC was faster.

HOWEVER the GCC he tested against was GCC 4.2, a ~5 year old version of GCC which is the version OSX ships with (he was using OSX) so the tests as comparative between GCC and Clang/LLVM of today were pointless.

It should also be noted that Firefox as used on people's machines today gets a large performance boost from profile-guided-optimization (remember back when people noticed that win32 Firefox under wine was faster than native Firefox on Linux? This was because of the Linux versions not being compiled with profile-guided-optimization at the time), and this optimization is not available for Clang/LLVM (though iirc there's a GSOC project for it this summer).


One area where Clang really shines is compile time - it's faster than gcc, at least a little [1].

The claims about who has faster binaries are pretty difficult to judge - it seems they really are about equal. It may be highly superscalar CPUs with instruction reordering and register aliasing hide the difference.

[1] http://gcc.gnu.org/ml/gcc/2012-02/msg00134.html (probably unbiased) and http://clang.llvm.org/performance.html (probably biased)


My code consists of tight loops used for numerical simulation. Clang runs about 2x slower. Hence I conclude that Clang is bad for optimizing tight loops.

Many of the Clang vs. GCC tests are clandestinely skewed towards llvm because they involve code that does not benefit from low level optimization.

Many of the people who work on GCC are scientists who want tight loop performance while many of the folks who work on clang want a BSD license.


It depends a lot on the use-case. For my hobby project (numerical stuff, C++) I got a speedup of more than 10% by moving to Clang. Huge stuff. I spend ~50% of my time in one hot function, though, and it's entirely possible that GCC generated better code for the rest of the project.

As usual, the only reliable way to know which compiler generates better code for your program is to run benchmarks.

For what it's worth, I wasn't blown away by the compile times or error messages when I moved to Clang. I think GCC is getting a lot better, but I'd also learned to live with its failings regardless.


For me it's mainly the error messages, either Clang/LLVM has gotten slower in compiling or GCC has gotten faster, but it's not a big 'percieved' difference for me anymore. I think the Clang error messages are more informative and also that the colored output makes it easier to read.

Performance-wise though I still generally get ~5-15% better speed on generated code with GCC (corei7).


A: Modular design. You can change everything, modify to make your own compiler and even include on a proprietary project if you want(license much more permissive than GPL)).

It lets you interpret C and C++, if you want.

It lets you compile in C, C++ to bytecode like java if you want, native code if you want too.

It can compile JIT fast things like OpenCL or javascript.

D: It is huge for a compiler. I believe gigabytes or so.


I was a bit surprised by Stallman's statement

"One of our main goals for GCC is to prevent any parts of it from being used together with non-free software. Thus, we have deliberately avoided many things that might possibly have the effect of facilitating such usage"


Clang is not gigabytes big. Even the uncompressed source code for it and LLVM (which are very big) aren't in the gigabytes.

http://llvm.org/releases/download.html#3.0


If you want a more technical review of LLVM, I think this is a very good one: http://www.aosabook.org/en/llvm.html (Chris Lattner is the creator of LLVM)




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: