Fundamentals 5 min read

Why the Linux Kernel Is Switching to Modern C (C11) in Version 5.18

The Linux kernel community is debating moving from the outdated C89 standard to a modern C standard—likely C11—for the upcoming 5.18 release, driven by bug fixes, macro safety concerns, and support from key developers.

21CTO
21CTO
21CTO
Why the Linux Kernel Is Switching to Modern C (C11) in Version 5.18

According to recent Linux kernel mailing‑list discussions, the community is considering moving the kernel from the legacy C89 standard to a modern C standard, potentially C11, in the upcoming 5.18 release.

The kernel still relies on the 1989 C89 standard, which predates the project, and developers see this as outdated. A patch by Jakob Koschel fixing a speculative‑execution vulnerability in the kernel’s linked‑list implementation highlighted issues with the current macro usage.

struct list_head {
    struct list_head *next, *prev;
}

The list_for_each_entry() macro, commonly used to iterate over lists embedded in other structures, can leave the iterator usable after the loop, causing bugs such as one in the USB subsystem.

struct foo {
    int fooness;
    struct list_head list;
}
struct foo *iterator;

list_for_each_entry(iterator, &foo_list, list) {
    do_something_with(iterator);
}
/* Should not use iterator here */

Koschel rewrote the problematic code to stop using the iterator after the loop. Linus Torvalds initially did not see the connection to speculative execution, but later realized the iterator must be declared outside the loop’s scope.

Linus suggested a block‑scoped variable, which C89 does not support, prompting discussion of adopting C99 or C11. Arnd Bergmann argued for C11, noting its multithreading support and safety improvements, and that GCC 5.1 already supports it.

Linus agreed, and after confirmation from Bergmann, announced that kernel 5.18 will try using the C11 standard, though the transition may bring surprises, as warned by Jonathan Corbet.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linux kernelkernel-developmentSpeculative ExecutionC11C standards
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.