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".
Right. Given how many actual kernel developers are opposed to C++ in the linux kernel, how much do you want to bet that having to know C++ well enough to avoid all the footguns is a worse option for them than just sticking to C?
I don't bet when it comes to serious and dependable development. If people prefer to stick with C then be it. But in that case I insist on never getting any more breaking news about the next security vulnerability like goto fail;
Every time when I was forcibly thrown back into C like when doing embedded environment development for f.e. embedded controllers I thought: this total lack of expressive power is so daunting and unsafe (and a total waste of precious developer time). Seeing this as normal and totally acceptable must be what they call the "Stockholm syndrome".
7
u/tesfabpel Jul 13 '22
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".