C++ In The Linux Kernel?
Written by Harry Fairhead   
Sunday, 14 January 2024

It might come as a surprise to many a new hand, but the Linux Kernel is written in C and not just as a passive preference - Linux is actively pro-C and anti-C++. Or it always has been.

C was the best choice for a systems programming language back when Linus Torvalds started work on Linux. Since then it has been suggested that allowing the C to evolve into  C++ is an obvious road to travel. Enthusiasm for C++ at the time was growing and it still is fairly strong despite the misgivings of some programmers. One programmer in particular has always been very opinionated about C++ and that programmer is a very important one - Linus. To quote the man himself:

"C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C."

This was back in 2007, but I doubt that he has changed his mind.

If you use C++ and are enthusiastic about it then you probably still feel insulted by his remarks, but in this day and age of Rust and other safer languages they are even more realistic.

All of this would be history but for a post on the mailing list that reopens the can of worms. The new argument seems to be that C++ in 2024 isn't the horror that Linus is complaining about:

"Both C and C++ has had a lot of development since 1999, and C++ has in fact, in my personal opinion, finally "grown up" to be a better C for the kind of embedded programming that an OS kernel epitomizes. I'm saying that as the author of a very large number of macro and inline assembly hacks in the kernel."

Personally I don't agree. C++ is a worse mess than it ever was. C is not a safe language but its screwups are usually easy to see. In general C bugs are not deep. C++ on the other hand is capable of being used in ways that defies the mind of man to contemplate. To my mind C++ hasn't so much "grown up" but been overgrown with efforts to extend and fix its problems.

This is the reason we need Rust or something very like it. Of course, there are moves to allow Rust to be used in the kernel and this might well be the reason that C++ has raised its head again - if you going to let Rust in, then let C++ in. They are very different propositions.

You can read the exchange on the mailing list - so far there has been no word from Linus...

  • Harry Fairhead is the author of Applying C For The IoT With Linux which is  the book you need if you are programming for Single Board Computers (SBCs) that run Linux, or if you do any coding in C that interacts with the hardware and Fundamental C, where he takes an in-depth look at C for use in any close-to-the-hardware context.

More Information

https://lore.kernel.org/lkml/3465e0c6-f5b2-4c42-95eb-29361481f805@zytor.com/

https://harmful.cat-v.org/software/c++/linus

Related Articles 

Rust Gets Into The Kernel

Linus Returns A Reformed Character

Linux Adopts New Code of Conduct; Linus Apologizes and Takes a Break

Linus On Linux And Strong Language 

GCC Gets An Award From ACM And A Blast From Linus        

Linus Torvalds Receives IEEE Computer Pioneer Award       

Linus Torvalds interview - the early years       

Linus Torvalds is now a US Citizen  

Linux To Move To C11

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


MongoDB 8 Reduces Memory Use And Increases Speed
07/10/2024

MongoDb 8 has been released, and the developers have said this is the most secure, durable, available, and performant version of MongoDB yet, with significantly reduced memory usage and query times, a [ ... ]



Raspberry Pi Beaten To It With Pico Plus 2
02/10/2024

RPi recently announced the Pico 2, but while we are all waiting for the more useful Pico 2W, with WiFi, the tiny Pimoroni outfit has produced something better - the Pico Plus 2 with WiFi. What is goin [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

 

 

 

 

 

 

 

 

 

 

Last Updated ( Monday, 15 January 2024 )