5 ms·
Why would one prefer to use LLVM over GCC?
by mikevm 14y ago
Why would one prefer to use LLVM over GCC?
- msutherl 14y agohttp://clang.llvm.org/comparison.html http://clang.llvm.org/comparison.html
- jetti 14y agoAs somebody who is learning C++ and decided to go with clang, the error reporting is absolutely phenomenal. It tells me not only what line errors are on but also makes suggestions as to how to fix it. I don't ever recall GCC having very helpful error messages.
- pooriaazimi 14y agoAgree. Clang vs. GCC is like PostgreSQL vs. MySQL (regarding usefulness of error messages).
- belorn 14y agoHowever, in C language features GCC becomes PostgreSQL and Clang becomes MySQL (Things like nested functions to name one).
- eliben 14y agoIs that C language features or compiler-specific extensions? Arguably, sticking to the standard is actually the better alternative here in terms of portability.
- pooriaazimi 14y agoYou're right - it's a compiler extension to a language (apparently) called "GNU C"[1]: http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html Seems like a very nice feature though. [1]: First time I've heard this term. I'm not sure how I feel about it.
- koenigdavidmj 14y agoYou can usually use "-std=c99" to ban features of concern.
- mikeash 14y agoClang has blocks, which, while different, are at least an arguably superior replacement for gcc's nested functions.
- deleted 14y ago[deleted]
- chc 14y agoGCC has nested functions, which most GCC users hate. Clang has blocks, which are at least widely used on OS X at least and proposed for standardization. I'm not sure this is a point in GCC's favor.
- wsc981 14y agoAs an Objective-C (iOS) developer, I really love blocks. I thought the syntax was kind of weird when starting to learn it, but it's grown on me. I really hope ObjC blocks will become part of the C standard someday. If I remember people have proposed C++ lambdas to become part of the C standard as well. It will be interesting to see which one (if any) will win in a standardising process. More info on ObjC blocks vs C++ lambdas in this blog posting: http://www.mikeash.com/pyblog/friday-qa-2011-06-03-objective-c-blocks-vs-c0x-lambdas-fight.html http://www.mikeash.com/pyblog/friday-qa-2011-06-03-objective...
- TallGuyShort 14y agoLLVM has a BSD-license. This might be a big deal for some people from a philosophical perspective, but at a more practical level it's great when you need to embed a compiler in your product.
- belorn 14y agoWhat kind of products allow users to compile and run custom C code, but would feel constrained by the GPL? Any examples (OSX excluded)?
- stusmall 14y agoXCode. GCC is now under GPLv3. I've got a feeling the patent issues in v3 give Apple lawyers a serious rash. Also with it being under BSD, they can write their own closed source extensions or reuse portions of their code in their own projects.
- TallGuyShort 14y agoI'm working on an Apache-licensed product that uses some of it's libraries for code generation.
- erichocean 14y agoIt has nothing to do with "custom C code". Any tool with a custom language (or equivalent) that wants a runtime JIT for the language and code compilable to LLVM IR would need to link in the compiler libs to do that. Custom DSLs are everywhere. For example, OpenShadingLanguage compiles shaders on the fly as part of a physically-based renderer, and then JITs them at runtime with LLVM. Linked in are the LLVM libs and a bunch of C code that is converted to LLVM IR and accessed by the shaders. The whole lot is linked and JITd together, enabling interprocedural analysis, inlining and a bunch of other compiler optimizations (e.g. constant folding). The resulting shaders are about 25% faster than their previous, hand-coded C shaders. IOW, lots of products benefit from having a compiler toolchain at runtime they can link with their program. GPL license or not, GCC isn't made to do that.
- pohl 14y ago
- kryptiskt 14y agoBecause both LLVM and Clang are librarified from the off, so you can hook them into your own code and use as much or as little of them as you want. You can insert your own passes, make your own drivers, add your own analyses to the static analyzer (http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf). Or use it to get information to show in an IDE.