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



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.



Gain A Python Professional Certificate From edX

From now until the end of February edX is offering a saving of up to 30% on some of its expert-led courses and program bundles, which is a good incentive for going from thinking about enrolling to act [ ... ]

OpenSilver 2.1 Adds F# Support

OpenSilver 2.1 has been released with improvements including support for F#. The open-source alternative to Silverlight is capable of running large, complex legacy applications, as well as newly writt [ ... ]

More News

raspberry pi books



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











Last Updated ( Monday, 15 January 2024 )