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


Azul Intelligence Cloud Expands Support
02/05/2024

Azul has announced that its cloud analytics solution, Azul Intelligence Cloud, now supports Oracle JDK and any OpenJDK-based distribution. More DevOps teams will now benefit from its ability to b [ ... ]



Women Who Code Closing For Lack of Funding
24/04/2024

Women Who Code the US-based non-profit organization that since its foundation in 2011 has advocated for women and diversity in technology, has announced its imminent closure due to critical funding cu [ ... ]


More News

raspberry pi books

 

Comments




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

 

 

 

 

 

 

 

 

 

 

Last Updated ( Monday, 15 January 2024 )