Red Hat Developer Posts Patches As A Baby Step To Converting Linux Kernel To C++

David Howells posted the set of 45 patches to "convert the kernel to C++", with these patches fixing real coding issues and targeting the GCC 8.0 C++ compiler. At this stage though the C++ compiler gets as far as compiling init/main.c to a file... Obviously just the tip of the iceberg. These 45 patches have various fixes for the code to clean up arguments, ensuring the code would be happy under a C++ compiler, etc and amount to around one thousand lines of code shifted.
He wrote on the mailing list:
Seriously, though...So this is likely not a real initiative being pursued by Howells or Red Hat, but has uncovered some legitimate minor issues along the way to which there are now fixes for review on the mailing list.
Apart from the cleaner inline functions allowed by templating, I'm not sure there's a lot of the C++ language that we would want to use in the kernel unless we want to go for more advanced classes implementing interesting types.
We could, for example, wrap things like userspace pointers, __be numbers, ioport addresses and control access to them that way, but I don't know that it gains a whole load that sparse doesn't give us.
And finally, doing this did find a few minor things that can be fixed.
For anyone who doesn't read the Linux kernel mailing list frequently, Linus Torvalds on well more than one occasion has gone off on rants about his distaste for C++... He has gone as far as saying "C++ is a horrible language," so don't expect the kernel to switch over to C++ under his watch. Some developers though have voiced their dissenting beliefs in the past about potential benefits to the Linux kernel in a C++ world.
74 Comments