Why is clang not used more?

14,851

Solution 1

My question is why this tool is not used/mentioned more than it is?

It's probably because of history, and because how we humans generally behave.

Traditionally gcc has been the only real (free) compiler that can be practically used to compile C programs on atleast all the free *nix clones out there. It's what virtually all the base system and kernel of linux, *BSD, now probably OSX, and others are compiled with.

While flaws are here and there, basically this means: gcc works. And if it isn't broken, don't fix it. Out of this, you now have a huge user base, it's easy to get help with gcc, there's a lot of people that have used gcc, that are working on gcc itself etc.

Generally, if you want to switch a huge community from something they're used to, to something else, that "something else" have to be *significantly" better. Just "better" is often not reason enough. I think you can find examples of this in many areas of society.

clang is newer, some people will just be suspicious if it's up to the task, if it has bugs, if it produces slower code etc. - it seems to be in the human nature to be suspicious - new things are scary. Many don't even know about clang, many don't care because they're happy with gcc.

Though, if you rather want to use clang, go for it - error messages are indeed "better" and easier to understand vs gcc.

Solution 2

The clang front end is relatively new. For example, the 2.8 release in October 2010 marks the completion of the C++ 98/03 support.

It seems likely that with increasing maturity, there will be an increasing adoption. For example, there is ongoing work on making the FreeBSD OS (and other BSD OS's) build with clang, eliminating a dependence on GCC/G++.

Apple are pushing the LLVM/clang combination. It seems likely that they will cease to support their old GCC toolchain branch (based on 4.2) and come to depend solely on clang tools for OSX/iOS development.

Clang is also seeing increasing adoption in custom compilers for C-like languages (e.g. shader language compilers for OpenCL)

Solution 3

LLVM has been around for a while, but — at least in my neck of the woods — it has only risen to prominence very recently, possibly due to the fact that Apple has been pushing heavily of late to replace gcc with Clang in their own tool-chain.

Also, I believe it's C++ support has only recently become production-grade. EDIT: It appears that it isn't even that yet. (See comments below.)

Another factor might be that LLVM is largely backed by a single vendor, towards which non-Apple developers have an innate mistrust.

Solution 4

My question is why this tool is not used/mentioned more than it is? Is it that it is so new compared to the usual suspects…

This is exactly the reason. It is still new and core functionality is still being actively developed. Remember that existing projects may be making use of compiler-specific features – or using libraries which do – and developers are, in any case, loath to change working tools for experimental ones that may have unexpected bugs or unknown performance/size/etc. tradeoffs, even when the new tools are increasingly getting better every day.

Solution 5

As a student programmer I find it a total godsend mainly due to it's helpful and understandable error messages. I use it mainly for programming in C, though I am beginning to branch out into C++ also using Clang.

As to why is it not mentioned more, I suspect it is since GCC has been established for so long, for most users it is THE compiler. GCC for me works fine except for it's extremely cryptic error messages which as a student does throw me off quite a bit.

Overall I do highly recommend Clang for use by both students and developers. Since it is now the official compiler for Apple and Xcode, I suspect it's use and name recognition will quickly pickup. FreeBSD seems to have also adopted it as their main compiler though I suspect that will have less impact on it's popularity than it's adoption by Apple.

Addendum: Due to the competition from Clang, the clarity of the error messages in GCC 4.8 and 4.9 has shown a significant improvement; though I still find Clang a little more lucid, the gap however has narrowed significantly.

Share:
14,851
Daniel Standage
Author by

Daniel Standage

Husband, father, scholar, scientist, programmer, lapsed musician, flipper of pancakes, baker of biscuits.

Updated on June 06, 2022

Comments

  • Daniel Standage
    Daniel Standage almost 2 years

    I've done a fair amount of programming in C/C++ before, but nowadays it only accounts for a small percentage of the programming I do (scripting languages are much better suited for a lot of the work I do). I worked on some C programming projects the last few days and was surprised how many little syntactical details I kept forgetting. What's worse is that cc/gcc typically had cryptic or non-informative error messages about these issues (sorry I can't remember any specific examples).

    I learned about the clang compiler not too long ago and decided to try that. The error messages were much clearer and helped me identify and fix the problems in my syntax. My question is why this tool is not used/mentioned more than it is? Is it that it is so new compared to the usual suspects (cc/gcc), or is it that it doesn't support features that they support, or is it just harder to obtain? I have a hard time believing that last one, since it was installed with the dev tools on my iMac and required a single command (sudo apt-get install clang) to install on my Ubuntu box.

  • bdonlan
    bdonlan over 13 years
    Keep in mind also that C++ support has only been completed VERY recently, and may still have bugs lurking around. And debug symbols still need work too (I've heard rumors about the debug symbol output being 5x larger than GCC's...)
  • AntonyFalegk
    AntonyFalegk over 13 years
    @bdonlan, debug symbol size problem is only on Linux btw.
  • Tamás Szelei
    Tamás Szelei over 13 years
    It's not production-grade, just feature complete (C++03). E.g. it can't compile Qt correctly AFAIK (it does compile but unit tests show regressions).
  • Fred Nurk
    Fred Nurk over 13 years
    @bdonlan: I tried to say that with 'experimental', but it should be emphasized. Thanks.
  • Alex S
    Alex S over 13 years
    @Tamás: Thanks for the comment. I've amended my answer.
  • David Rodríguez - dribeas
    David Rodríguez - dribeas over 13 years
    +1, and I would add a second one just for the last remark! backed by a single vendor, towards which non-Apple developers have an innate mistrust.
  • grrussel
    grrussel over 13 years
    Quote from the LLVM/Clang 2.8 release notes "Clang is considered a production-quality compiler for C, Objective-C, C++ and Objective-C++ on x86 (32- and 64-bit), and for darwin-arm targets". So, maybe production quality is platform dependent. I certainly expect it to work best on OSX and its targets, as Apple is the major backer and the Linux/Unix/Windows support is in contrast community driven.
  • Vinnie Falco
    Vinnie Falco over 11 years
    Out of all the areas of a program that need "optimizing", I would imagine that the performance of exiting the app is of the least concern.
  • Jack
    Jack over 11 years
    The optimization here are 1) by the compiler when it seen "nonreturn" attribute; 2) by me when remove dead code -Wunreachable-code
  • Apteryx
    Apteryx over 2 years
    In most place is obviously untrue, even according to the link you provided yourself.