r/C_Programming • u/Negative_Effort_2642 • Apr 03 '26
Question Clang vs gcc
I am wondering what do you guys use and why? And additionally what flags do you use bcs of c lack of safeguards?
51
Upvotes
55
u/[deleted] Apr 03 '26 edited Apr 03 '26
I mostly use gcc, my standard flags I always use are
-Wall -Wextra -Wpedantic -Werrorand-fsanitize=address,undefined,leakfor running during development, remove the sanitizers for a release build. Some more may be used depending on what I do.20
u/Farlo1 Apr 03 '26
In production code: both. Each compiler has its own up/downsides and sometimes one will have better warning coverage than the other, so it’s helpful to compile using both just to make sure things are correct.
For learning or hobby projects it mostly doesn’t matter, use what you’re comfortable with. Until recently Clang had much better support for sanitizers and LTO, but that gap has shrunk as well.
15
u/greg_kennedy Apr 03 '26
clang on FreeBSD, gcc on Linux, MSVC on Windows. Basically, whatever comes standard with the OS. It's more likely another user will already have that by default.
I prefer clang, and get annoyed when one of the FreeBSD ports "requires" gcc due to Makefiles hard-coding it when it isn't actually necessary.
12
u/EpochVanquisher Apr 03 '26
Both, plus MSVC. I use GCC on Linux, Clang on Mac, and MSVC on Windows.
Flags: -Wall -Wextra -Wmissing-prototypes -Wpointer-arith -Werror=implicit-function-declaration.
There’s one flag which I definitely don’t use, which is -Wpedantic. The flag is useless. I’ve even examined the GCC source code to see every place where it’s used, and they’re all basically useless warnings.
4
u/pskocik Apr 03 '26 edited Apr 03 '26
I personally test debug and release builds in parallel on gcc, clang, and tinycc.
Highly recommend. You'll catch bugs easier and your codebase will be more robust and more portable.
I have most warning flags on (-Wall, -Wextra, -Wconversion, -Wsign-conversion, -Wdeprecated-declarations, ...) with a small number explicitly disabled cuz they were too much of a pain to silence through code (namely, -Wno-missing-field-initializers -Wno-unterminated-string-initialization).
I use a buch of f flags, some of which are a bit opinionated: -fno-common -fno-semantic-interposition -fstack-clash-protection -fno-asynchronous-unwind-tables -fno-stack-protector -fdollars-in-identifiers -fcf-protection=none -fdiagnostics-color=always.
I don't do -Werror. Sometimes I go through flurries of wild experimentation when I'm transiently getting a bunch of warnings, and I don't like that stopping my build altogether.
3
u/rapier1 Apr 04 '26
gcc because that's the compiler almost all of my users will be using if they are building from source. The ones that are using clang hopefully know enough to submit a bug if they run into issues. Since it's the default I need to know the specifics about how the code will perform, compile, etc. Also, I use launchpad, copr, etc for distributing binary packages. Since those use gcc I use gcc.
I do use clang for static analysis though.
3
u/Flashy_Possibility34 Apr 04 '26
If you are using a Mac, unless you go out of your way to install gcc and override the default path, `gcc` is actually `clang`.
```
> gcc --version ~
Apple clang version 17.0.0 (clang-1700.6.3.2)
Target: arm64-apple-darwin25.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```
2
u/arjuna93 Apr 03 '26
I use gcc as long as it works. On recent macOS it is hard to avoid clang.
2
u/imdibene Apr 03 '26
clang on MacOS and gcc on Linux
1
u/UltimaN3rd Apr 03 '26
I use Clang 22 because it has the defer technical specification implemented. I used GCC before because I could use defer with a macro, but the clang implementation is a bit better since it creates a compile error if you try to goto over a defer statement.
0
u/chrism239 Apr 04 '26
I can’t understand why you’d choose to not use -Werror
0
u/xMarcelo Apr 06 '26
Except when building with rust for w64, clang. Mingw-w64 comes w/ gcc :(