Difference between GCC Clang

Asked

Viewed 1,466 times

8

The systems based on Unix (a large majority), usually use the GCC, to compile the files in C, but I also possessed the Clang for the same purpose.

There is difference when compiling some project using GCC and Clang?

  • Clang was designed to be able to replace GCC. It is an open source project with major contributors such as Apple, Microsoft, Google, ARM, Sony, Intel and Advanced Micro Devices (AMD). Website with a comparison between GCC and Clang: http://gcc.gnu.org/wiki/ClangDiagnosticsComparison

  • 1

    I like to use the -Weverything with Clang. Same -Wall -Wextra with gcc still leaves some warnings disabled.

1 answer

1


To answer your question we need to make a brief reflection.

  1. -The Clang deals only with the front-end , "let’s say it deals basically with the options and the links paths to the files, "for the compilation itself, it uses the LLVM which is responsible for the lexical, syntactic and semantic analysis of the compilation process. The GCC is a complete set with front-end and back-end.

  2. The Summary of Clang Options although it has many basic options equal, it also contains compilation options different from Summary of GCC options.

  3. GCC beyond C, C++, Objective-C, has front-end for other languages like , [Fortran, Java, Ada, and more recently Go], the names may change like g++ and Gfortran but still coninuam being part of the GCC project. Clang has front-end only for C [C, C++, Objective C and Objective C-based languages++].
  4. Since LLVM and GCC are different compilers, they have different implementations, so the basic instruction set order generated is different. This affects both compilation time, since they have different implementations, and execution time of a program, since they go through different optimization steps and generate different basic instructions.

Well said that, I hope it has become clear that although the basic commands be equal, compiling a program using GCC is different from compiling a program using Clang + LLVM.

  • 1

    Just to complement Gabriel’s responsibility, although the code of the final program is different, the result of running the program on both compilers is expected to be the same since they are compiling the same program in the same language.

  • The first point is all wrong. Clang is a front-end for the C language families (C, C++, Objective-C etc), which takes care of lexical, syntactic and semantic analysis and generates an unadjusted IR. LLVM is a back-end that optimizes and converts IR to some ISA of a target architecture.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.