Clang advantages over the GCC compiler:
Faster compile times
Less compile output
The error prompt is more friendly , such as clang can directly indicate a relatively simple error location and the way it "thinks" in the compilation process.
built-in static analysis tools allow static analysis of code (CLANG-ANALYZE). That's what GCC can't do.
Focus , because clang only needs to complete lexical and syntactic analysis, code optimization and machine code generation work is done by LLVM. So clang can do one thing more intently than GCC, which is all wrapped up by himself. This structure also allows clang to be taken out of the box and used in other programs to become an embedded C + + parser for other apps (mostly Ides). For the IDE, code completion, refactoring is an important function, but if there is no underlying support, only using tags analysis or regular expression matching is difficult to achieve, clang just act as this role. In this way, the editor tool can use the same parser as compiler to complete the edit-time syntax check. GCC is not very convenient to do this. For historical reasons, GCC is a single executable compiler that has completed all the processes from preprocessing to final code generation, and many of the information in the middle is not reused by other programs.
Benefits of GCC:
· Some of the software compiled with Clang will have an inexplicable error, but can be compiled with GCC.
· GCC has been preparing to use C + + for modularity before 5.0, expecting a breakthrough in GCC's 5.0 and a short board that cannot be modularized.
faster compilation, smaller compilation output, and more friendly error hints。 Especially in the more extreme cases.
Two years ago wrote a scheme interpreter, lexical analysis and parsing part about 2000 lines, using boost.spirit--a heavily dependent C + + template meta-programming framework. The situation when compiling with g++ 4.2 was:
- Very slow to compile: 20 minutes for full compilation
- High Memory consumption during compilation: a single g++ instance memory peak consumption of more than 1G
- The intermediate output is great: all the. o files are compiled together about 1~2g,debug link products over 200M
- Compilation errors are extremely difficult to understand: compile errors often up to dozens of k, basic unreadable, the most fatal is the compiler error often grow to be g++ truncation, see the real error location, basically can only rely on naked to see the code to debug
Here, whether I use spirit or not, there is a problem with the spirit framework itself. I was trying to clang because I couldn't stand the g++. At that time with the clang 2.8, just can be fully compiled boost, the effect let me very satisfied:
- The compilation speed is significantly improved, remember about the g++ 1/3 or 1/4
- Memory consumption during compilation doesn't seem to be a big difference.
- Intermediate outputs and final link products, remember also g++ 1/3 or 1/4
- Compilation errors are more readable than g++, and at least there is no problem with the truncation of compilation errors too long.
At that time the biggest drawback is that clang compiled executable files can not be debugged with GDB, need to use the debugger when you have to use g++ to compile again. But this problem was solved later, I do not know whether the clang support GDB or GDB support the clang. At least I am currently in Ubuntu under the clang 3.0 compiled binary files can be successfully debugged with GDB.
Finally, other students have also talked about, that is, Clang uses the BSD protocol. This is an important reason for Apple to subsidize LLVM and FreeBSD to phase out GCC swap clang. Clang vs GCC (GNU Compiler Collection)
Pro ' s of GCC vs Clang:
- GCC supports languages that Clang does isn't aim to, such as Java, Ada, FORTRAN, Go, etc.
- GCC supports more targets than LLVM.
- GCC supports many language extensions, some of which is not implemented by Clang. For instance, in C mode, GCC supports nested functions and have an extension allowing vlas in structs.
Pro ' s of clang vs GCC:
- The Clang ASTs and design are intended to being easily understandable by anyone who's familiar with the languages involved a nd who have a basic understanding of how a compiler works. GCC has a very-codebase which presents a steep learning curve to new developers.
- Clang is designed as a API from their inception, allowing it to be reused by source analysis tools, refactoring, IDEs (etc) As well as for code generation. GCC is built as a monolithic static compiler, which makes it extremely difficult to use as a APIs and integrate into other Tools. Further, its historic design and current policy makes it difficult to decouple the front-end from the rest of the compiler .
- Various GCC Design decisions make it very difficult to reuse:its build system are difficult to modify and you can ' t link mult Iple targets into one binary, you can ' t link multiple front-ends to one binary, it uses a custom garbage collector, uses Global variables extensively, is not reentrant or multi-threadable, etc. Clang has none of these problems.
- Clang does not implicitly simplify code as it parses it like GCC does. Doing so causes many problems for source analysis Tools:as One simple example, if you write "X-x" in your source code, TH E GCC AST would contain "0", with no mention of ' X '. This is the extremely bad for a refactoring tool, wants to rename ' X '.
- Clang can serialize its AST out to disk and read the it back into the another program, which are useful for whole. GCC does not has this. GCC's PCH mechanism (which is just a dump of the compiler memory image) was related, but was architecturally only able to re Ad the dump back into the exact same executable as the one of that produced it (it's not a structured format).
- Clang is much faster and uses far less memory than GCC.
- Clang have been designed from the start to provide extremely clear and concise diagnostics (Error and warning messages), an D includes support for expressive diagnostics. Modern versions of GCC has made significant advances in this area, incorporating various Clang features such as Preservin G typedefs in diagnostics and showing macro expansions, but GCC was still catching up.
- GCC is licensed under the GPL license. Clang uses a BSD license, which allows it to being embedded in software so is not gpl-licensed.
- Clang inherits a number of features from it use of LLVM as a backend, including support for a bytecode representation for Intermediate code, pluggable optimizers, link-time optimization Support, just-in-time compilation, Ability-link in mul Tiple code generators, etc.
- Clang's support for C + + is more compliant than GCC's in many ways.
- Clang supports many language extensions, some of which is not implemented by GCC. For instance, Clang provides attributes for checking thread safety and extended vector types.
The difference between clang and GCC under Linux