Why Linux Is Moving Its Kernel to C11 and What It Means for Developers
The Linux kernel, long stuck on the 1989 C89 standard, will upgrade to C11 starting with the 5.18 release, a change driven by a subtle bug in list traversal macros and Linus Torvalds' decision after community discussion.
After decades of using the 1989 C89 standard, the Linux kernel community announced that the kernel will be upgraded to the C11 language standard, expected to take effect after the 5.18 release in May 2024.
Bug that triggered the change
A recent discussion revealed a subtle bug in the list_for_each_entry() macro, which leaks the iterator variable outside the loop because C89 does not allow variable declarations inside the loop header. The bug manifested in the USB subsystem.
struct list_head {
struct list_head *next, *prev;
};
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 */Jakob Koschel submitted a patch that stops using the iterator after the macro, fixing the issue.
Convincing Linus Torvalds
Linus initially dismissed the patch, not seeing its link to speculative‑execution vulnerabilities. After Koschel’s detailed explanation, Linus recognized that the root cause was the inability to declare the iterator inside the loop, a limitation of C89.
Because C89 is too old and some legacy gcc versions caused problems, the community considered moving to C99, but ultimately decided on C11, which is newer yet still widely supported. The kernel now requires gcc 5.1 or newer, eliminating the earlier compiler constraints.
Core developer Arnd Bergmann argued that C11 is the most practical target; moving to C17 or C2x would break compatibility with gcc 5/6/7. Linus agreed, saying “Okay, remind me to try it early in the 5.18 merge window.” The transition may introduce unexpected bugs, but if successful, the next kernel release will officially use C11.
References:
1. https://lwn.net/SubscriberLink/885941/01fdc39df2ecc25f/
2. https://news.ycombinator.com/item?id=3045963
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
