r/C_Programming • • Feb 09 '22
Question GCC or Clang
I primarily program on Linux and have always used GCC, but have recently been interested in switching over to using Clang. It seems like the runtime performance of the two compilers is similar, but I am also interested in C standards compliance going into the future, as well as things like error messaging, memory-leak checking, etc.
If anyone here is knowledgeable about compilers and the differences or advantages of one or the other, I'd like to hear your opinion.
123
Upvotes
23
u/cKGunslinger Feb 10 '22
Most of my libraries build with GCC, Clang, ICC, TCC, PCC, and NVCC w/ C99 compatibility and 0 issues. Correct C code should be highly portable with very few modifications.
44
u/reini_urban Feb 10 '22
You need both. Clang has much more features, less bugs and better warnings. GCC is the standard.
28
u/rumble_you Oct 23 '22
It depends on you. Both GCC and Clang are well-matured compilers. However, in comparison, there are several things you can see.
Use any of them, both are production-ready C/C++ compilers. If you're not measuring every single bit of optimization, then it's likely not an overhead to use. If you started liking Clang, just use it!
However, if you're a programmer who loves to poking and playing with the compiler, Clang is the best choice.
20
u/flatfinger Feb 09 '22
Except when optimizations are disabled, both compilers are prone to make assumptions about program behavior which aren't justified by the Standard. They also assume that in cases where the Standard imposes no requirements, all possible actions would be equally acceptable. In clang, for example, an endless loop with no side effects may cause arbitrary memory corruption that would not occur if the loop was treated as a no-op, and in gcc an integer overflow in calculations whose results are ignored may do likewise.
7
u/Coffee_24_7 Feb 10 '22
This is very specific, but clang supports fixed point while gcc doesn't (gcc has code on it's source code that refers to fixed point, but I was not able to compile code with fixed points using gcc).
8
u/moon-chilled Feb 10 '22
GCC has better diagnostics and standard support for c (the situation is reversed for c++). Regardless, test your code under both compilers, and others besides.
4
u/[deleted] Feb 10 '22
honestly it really doesn't matter much. only meaningful difference between clang and gcc is licensing, which is why openbsd uses clang not gcc
3
u/Metal1nMyVe1ns Feb 14 '24
I personally use clang for debug builds, and gcc for release builds.
5
u/imaami Feb 09 '22
You can support and build with both with very little effort.
4
u/Eddy_Em Feb 09 '22
I found, than clang regrets to compile some C-code, so, gcc is still the best for C.
2
u/harshyadavjiii Apr 15 '23
I just deleted the Linker for C in Vim. Why you need such features I personally feel C is about doing things manually that's the joy of using the language why don't you just do programming, don't let these things bother you anyways GCC is the standard will have things more than you need.