Which C version is used in the Linux kernel?

As of Mon 2022-09-19, the Linux kernel is typically compiled with gcc -std=gnu11, which supports the GNU dialect of the 2011 edition of the ISO C standard.

Reference: https://www.kernel.org/doc/html/latest/process/programming-language.html

The kernel is written in the C programming language. More precisely, the kernel is typically compiled with gcc under -std=gnu11: the GNU dialect of ISO C11. clang is also supported, see docs on "Building Linux with Clang/LLVM".

Thanks to marc-2377 for posting a reference to that document in his answer.

Linus Torvalds has previously expressed a dislike for some features that were introduced in C99, such as mixing declarations and statements. At the time, the kernel was compiled with gcc -std=gnu89. I haven't investigated whether his attitude has changed since then. But that's a matter of coding style, not language standards.

I've deleted the bulk of my original answer since it's no longer relevant.


As of today (2022-09-19), the document at https://www.kernel.org/doc/html/latest/process/programming-language.html says:

The kernel is written in the C programming language [c-language]. More precisely, the kernel is typically compiled with gcc [gcc] under -std=gnu11 [gcc-c-dialect-options]: the GNU dialect of ISO C11.

(It also says Clang is supported as well.)


Stumbled over this while checking why the kernel isn't requiring C99 after 22+ years. There are parts of C99 used here and there in the kernel, but guarded by #ifdefs.

In any case, the following discussion (Sept. 2021) between Linus and some GCC people gives some relevant context, although it's mostly about standard-mandated header-includes (like <stdint.h>) and not so much about C language-features.

I find it a pity that the thread petered out, particularly the C99-<stdint.h> case with fixed-width integer types would be really helpful IMO.

More generally, now that the kernel also supports being built by Clang, it'd be great to move to a standard (by which I mean ISO C) baseline, rather than effectively a GNU-based one. And a more than 20 year old standard should really be enough IMO, even for the kernel...

Tags:

Linux Kernel