Linux to upgrade to C11

– as long as there are no problems. Linus Torvalds has long expressed a preference for the original C and a dislike or desperation for C++. Could he soften?


Probably not, because upgrading to C11 isn’t such a big step. If you select the correct compiler switches, you can write C11 as if it were C89, the current older version of C used in Linux and preferred by Linus so far.

A bigger step forward allows Rust to enter the kernel. It’s an ongoing story, but we basically have the first steps to allow drivers and other modules to be written in Rust. Why such an adventurous acceptance of a truly innovative language and so much conservatism when it comes to good old C? The answer is that Rust is a bit of a promising unknown. It seems worth a try, but later dialects of C and especially C++ are known to have big problems and are therefore much easier to dismiss.

C suffers from the problem of undefined behavior and its potential for aggressive optimization. The problem is that if something is defined as undefined, compiler authors can implement whatever they want and call it optimization. For example, if you put a null for loop in a program to introduce a slight delay, it can be optimized without any comment. To keep the null loop you need to make sure you set the correct level of optimization or mark a variable in the loop as volatile. This is not an example of undefined behavior, but it is similar. Linus was never satisfied with the lengths that compiler authors seem willing to go to win optimization contests:

“Listen, your compiler is doing some absolutely crazy things with dumping, including dumping a *constant*. For the love of God, this compiler shouldn’t have been allowed to graduate from kindergarten as a that baby “level delay levels here…”

The same kind of distrust applies to the new C standards. The problem seems to be caused by the standards and the compiler authors forgetting that, despite what many seem to believe, C is a high-level assembler and it should keep in touch with the Material. Some have claimed that all the standardization of C has made it unusable for OS development:

“… during the ISO standardization process, added many attributes of more conventional programming languages ​​and became less suitable for operating system development. Operating system programming continues to be done in non-ISO dialects of C.”

C99 in particular caused problems because it insisted on some of its language changes, which made it less backwards compatible with C89. There were so many issues that C11 is considered a “bug fix” which fixed things. That’s why Linus decided that a jump to C11 was better than going through C99. Of course there is C17 to consider and maybe soon C2x will get a value for x.

Interestingly, this decision was prompted by a potential bug caused by not being able to declare a variable as part of a for loop. This is something that C99 introduced:

“The reason this type of non-speculative bug can occur is that we historically didn’t have C99-style “declare variables in loops” of the loop, simply because we couldn’t declare the variable of iterator in the loop itself.” Linus Torvalds

So to allow variables to be declared in loops, Linux goes not to C99 but to C11.

“But we still don’t do ‘gnu99’, because we had weird problems with some older versions of gcc breaking documented initializers.” Linus Torvalds

So we might see C11 in Linux 5.18 as long as nothing unexpected appears.

Personally, I’d like to see an ISO C standard that recognizes that C is used with real machines and that under no circumstances is there ever any undefined behavior – only system dependent behavior.

  • Harry Fairhead is the author of Apply C for IoT with Linux which is the book you need if you program for single board computers (SBCs) that run Linux, or if you do C coding that interacts with hardware and fundamental Cwhere it examines C in depth for use in any hardware-near context.

More information

Move kernel to modern C

How ISO C became unusable for operating system development

usb: suppress use of list iterator after loop

Random panic in load_balance() with 3.16-rc

Related Articles

C Indefinite Behavior – Depressing and Terrifying (Update)

Linux adopts a new code of conduct; Linus apologizes and takes a break

Linus books a wrong flight so the conference moves

Linus on Linux and strong language

GCC receives an award from ACM and a breath from Linus

Linux turns 30

Linux at 30 – A penguin for your thoughts

Linus Torvalds on Linux Past, Present and Future

Minix inside!

Linus Torvalds receives the IEEE Computer Pioneer Award

GNU Hurd 0.6 released

Linux at 30 – A penguin for your thoughts

Linus Torvalds on Linux Past, Present and Future

Minix inside!

Linus Torvalds receives the IEEE Computer Pioneer Award

GNU Hurd 0.6 released

To be notified of 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


square



comments

or send your comment to: [email protected]

About Jon Moses

Check Also

NSA, CISA say: don’t block PowerShell, here’s what to do instead

Image: Getty Images/iStockphoto Cybersecurity authorities in the United States, United Kingdom, and New Zealand have …