Search code examples
linux-kernel

Which C version is used in the Linux kernel?


Does the Linux kernel use only the old C90 syntax or has it been optimized with C99 / C11 features?

I was wondering if the newest versions of C are used when possible.


Solution

  • 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.