Does anyone here use / love D? I’ve not taken the time to learn it, but from what I’ve seen it seems like I might enjoy it more than go but still less than Rust.
I really love it. I blogged about my attempt to really learn it in earnest:
I like it. Imho it is decent language with nice features.
This is interesrting, but I’m seeing / hearing SO much more lately about Clang, I wonder where GCC’s future lies.
GCC isn’t going anywhere as it supports a wide range of platforms and targets that are not the focus of Clang, among other reasons.
GCC also still produces faster code in most cases.
That has been my experience with ldc2 vs gdc: better optimisation in gdc for the cases I cared about.
Then why are the Linux kernel and some other projects switching to Clang? (Honest, stupid question. I’m WAY rusty on the C world :)
Great question! But Linux actually isn’t, sort of. Most Linux distros still ship with gcc-compiled Linux, except Android. I don’t know exactly why Android switched, but I wouldn’t be surprised if clang works better when compiling to ARM, since Apple built clang to compile iOS.
Linux has loads of reasons to compile with clang, even if the releases are still gcc-compiled. Just checking the warnings clang produces to compare with gcc provides a lot of value. But clang is more than a compiler, it’s a “set of reusable C++ libraries for building powerful source-level tools”, like the clang static analyzer. YouCompleteMe, the popular vim plugin does semantic code completion using libclang. So making Linux compile on clang opens up a lot of opportunities to use different tooling.
Building Linux with a different compiler has other advantages too, even if that compiler wasn’t clang. Compiling on multiple C compilers helps suss out obscure undefined or implementation-defined behavior bugs, or even compiler bugs! I don’t have an references on hand but the Linux on clang effort has found incorrect Linux code that happened to work due to one or more gcc bugs. There is an alternative rust compiler written in C++, mrustc that partially exists for this same reason.
Historically Linux has been gcc-only because it relies on lots of gcc features and extensions. Compiling with a totally different toolchain like MSVC is just a non-starter. Porting to clang has actually been viable because clang aims to be mostly gcc compatible, from compiler flags to special syntaxes to builtins, even down to many implementation-defined behaviors.
Lastly, getting Linux to compile with clang keeps the option of switching open. Linux might switch to clang one day if clang produces faster code than gcc on amd64. It’s not like Linux could switch overnight, it’s taken years of hard work to get this far. Android made the switch only recently. And even if most Linux distros did switch to building with clang, gcc would still be supported by Linux for many of these same reasons, in addition to gcc supporting many architecture targets that clang doesn’t (as mentioned by @trn).
I get it! So it’s more like Clang is a new, interesting toolchain that it makes sense to support because being compatible means people can use it for a variety of interesting analysis and optimization projects.
https://groups.google.com/a/chromium.org/d/msg/chromium-dev/bIWc8vFMF-w/wfMJsNHvDAAJ lists why the Chromium team pushed to get Chromium to compile with Clang on Windows. I forget how much overlap there is with reasons to favor Clang over GCC (having an open-source compiler certainly doesn’t apply there).
FWIW aren’t many projects like Linux aiming for compatibility with Clang and to build with both, rather than a complete switch-over?
No one else has seemed to mention licensing. I’ve always felt Clang was a response to the GPL licensing around gcc. After all, Apple has slowly been removing as much GPL code as possible from MacOS.
clang in my book is predominantly the response to GCC not wanting to modularise their system. Apple has issues with the GPL, but I would expect that to be more of a nice addon for them.
(See https://lwn.net/Articles/582697/ for background)
I sometimes wonder if the world would be a better place if we all just agreed that GPL-ish licenses were overly restrictive and counter productive and that BSD/MIT-ish licenses were Good Enough.
Among other things, Clang has a lot of great security features like (Cross-DSO) Control Flow Integrity. Android is using CFI for their version of the Linux kernel already.
Also, clang (well, any LLVM-backed compiler) is always a cross-compiler (and LLD is always a cross-linker), so you can completely avoid the nightmare of toolchain management (x86_64-unknown-linux-gnu-gcc-omgwtf)
Yeah, building cross compliation toolchains is a PITA to say the least.