Hacker News new | ask | show | jobs
by tialaramex 652 days ago
But that's an interesting point. Why is there a C++ compiler in the base? Do I find a long discussion on the FreeBSD list about whether it should have a C++ compiler? If not, why not?
2 comments

Because the System has to be self-hosting, remember it's a whole OS and not just the Kernel, and as you can see ~25% of src is C++, 62% C etc.

Rewrite everything C++ is not a small undertaking with (maybe?) not allot plus-sides, and even then you still need C++ because of LLVM. LLVM and GCC are both C++, and you have to compile the Compiler (self-hosting), and even if your a 100% Rust or C OS, you still need C++ because of LLVM/GCC....well if you want a modern compiler ;)

https://github.com/freebsd/freebsd-src

But when you look what all that C++ is doing in Base, it seems like it's basically LLVM and then a lot of code that's just there to help you write more C++ code. Not a whole lot of the FreeBSD Base userspace, the uilities and so on - is actually written in C++ despite that. It's getting a free ride because the compiler uses it.
>it seems like it's basically LLVM

Not important, you have to compile your Compiler fini, btw for Linux (just the Kernel) you need Perl ;)

Because most C compilers also include a C++ compiler, or that the compiler toolchain of choice for freeBSD happens to be LLVM (it was an old version of GCC before because newer version use an incompatible license, and before that I think gcc replaced pcc in the original bsd unix, the discussion to pcc with gcc is probably lost in time) that includes C and C++ compiler.

I am guessing that performance of current standalone C compiler is not as good as the one produced by compiler suit.

Following the conversation thread, rust also use llvm under the hood, but a customized one. Which would force the base system to have two versions of llvm.

It’s easy to build Rust with a stock llvm. You may just lose out on some back ported bugs that were patched in the fork the rust team maintains.