|
|
Subscribe / Log in / New account

Moving the kernel to modern C

Moving the kernel to modern C

Posted Feb 27, 2022 18:53 UTC (Sun) by rgmoore (✭ supporter ✭, #75)
In reply to: Moving the kernel to modern C by marcH
Parent article: Moving the kernel to modern C

C++ fans are fans of C++ because it lets you do whatever you want

Which is more or less the explanation Linus used for why he doesn't want to move to C++. It isn't about the technical side of the language; it's about excluding people who don't have the discipline to code the way he thinks the kernel should be coded.


to post comments

Moving the kernel to modern C

Posted Feb 27, 2022 19:05 UTC (Sun) by camhusmj38 (subscriber, #99234) [Link] (2 responses)

C let’s you do whatever you want. C++ is more restrictive than C. As I’ve said, the decisions made in the 1990s made sense then, but they don’t anymore. People who make the most performant, high security code code in C++ these days. There are no points in this game for being chads programming the way of the ancestors - on the contrary this can be harmful. This is particularly the case where people are reinventing language features using text substitution macros and a set of instructions to be carefully followed. Using the correct subset of C++ for Kernel mode is also a discipline - just as writing the correct type of C code is a discipline (using VLAs can overflow your stack for example, so don’t do it) - one that can be enforced with analysis tools and compiler switches.
It’s OK to say that you don’t want to do it because you don’t know how or are scared to learn new things. But it’s also OK for people to say maybe sheer obstinacy is not a reason to not consider an idea. The cult of personality in this area is not helpful.

Moving the kernel to modern C

Posted Feb 27, 2022 21:03 UTC (Sun) by marcH (subscriber, #57642) [Link]

> Using the correct subset of C++ for Kernel mode is also a discipline - just as writing the correct type of C code is a discipline (using VLAs can overflow your stack for example, so don’t do it) -

No, you're missing the point exactly like all other C++ fans. -Wwla is not a "discipline", it's a compiler flag. A discipline requires some mental effort whereas adding -Wwla to a configuration file requires zero human effort. The computer does all the work.

> one that can be enforced with analysis tools and compiler switches.

Great news: please share now the set of analysis tools and compiler switches that enforce the exact C++ subset kernel maintainers are willing to accept without increasing their code review workload that is already stretched past the limit. For at least all recent gcc and clang versions.

Good luck getting all kernel maintainers to agree on that C++ subset in the first place! So that was a trick question, sorry.

Moving the kernel to modern C

Posted Feb 28, 2022 8:55 UTC (Mon) by ballombe (subscriber, #9523) [Link]

VLA is a C99 extension.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds