He seems to be lacking a lot of knowledge about about C++ - at least in those days. And he also doesn't seem to care. And that's just bad because even a little bit of C++ without even touching the stuff he obviously is so scared of would improve kernel code a lot.
When I wrote my first Windows NT 4.0 kernel device driver in the mid 90s, I happily used C++ there because of the power of abstractions. And it didn't hurt!
Wikipedia says that the core part of the kernel is written in C and Assembly (just like Linux), while the graphics subsystem is written in C++.
Anyway, just quickly thinking about it, it makes at least some sense NOT to use C++ for a critical part like the kernel since it has many footguns that you need to always make attention to: for example, when you define a class or struct you have to be careful with unary constructors, copy / move constructors and assignments operators, copies are always behind the corner (but they can be optimized by the compiler). I think those are things that are important in a kernel and the copy-by-default semantic of C++ alongside with the copy constructor / assignment op (instead of the move-by-default in Rust or the copy-by-default of PODs in C without any copy constructor / assignment op) may create some "difficulties".
Wikipedia says that the core part of the kernel is written in C and Assembly (just like Linux), while the graphics subsystem is written in C++.
The Windoiws NT kernel was initially designed around 1990. The options were totally different then.
many footguns that you need to always make attention to:
When you write an OS kernel, we assume that you are careful and know what you are doing. :-)
Copying a POD in C++ is exactly the same as copy a POD in C. Adding member functions to the struct, instead of manually passing a pointer as the first parameter, also makes no difference (except possibly for improved readability).
If you want to make an object move-only, in C++ you can delete the copy constructor and copy assignment. In C you cannot.
-------------
Linus was obviously shown some low quality C++ code once, and decided that all C++ code is bad forever. And with that attitude, people who know how to write good C++ have not bothered to show him any of their code. So he has proven himself right.
26
u/MrRubberDucky Jul 13 '22
Source: http://harmful.cat-v.org/software/c++/linus