Skip to contentSkip to conversation

headers: Add check for C standard version

PATCH New Hanne-Lotta Mäenpää 1 participant 1 message Oct 26, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 headers: Add check for C standard version

Compiling the kernel with GCC 15 results in errors, as with GCC 15 the default language version for C compilation has been changed from -std=gnu17 to -std=gnu23 - unless the language version has been changed using

    KBUILD_CFLAGS += -std=gnu17

or earlier.

C23 includes new keywords 'bool', 'true' and 'false', which cause compilation errors in Linux headers:

./include/linux/types.h:30:33: error: ‘bool’ cannot be defined
via ‘typedef’

./include/linux/stddef.h:11:9: error: cannot use keyword ‘false’
as enumeration constant

Add check for C Standard's version in the header files to be able to compile the kernel with C23.

---
 include/linux/stddef.h | 2 ++
 include/linux/types.h  | 2 ++
 2 files changed, 4 insertions(+)
include/linux/stddef.h +2 -0
index 80b6bfb944f0..aa2cb3db3c06 100644
@@ -7,10 +7,12 @@
 #undef NULL
 #define NULL ((void *)0)
 
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L
 enum {
 	false	= 0,
 	true	= 1
 };
+#endif
 
 #undef offsetof
 #define offsetof(TYPE, MEMBER)	__builtin_offsetof(TYPE, MEMBER)
include/linux/types.h +2 -0
index 6dfdb8e8e4c3..931db48a7a09 100644
@@ -32,7 +32,9 @@ typedef __kernel_timer_t	timer_t;
 typedef __kernel_clockid_t	clockid_t;
 typedef __kernel_mqd_t		mqd_t;
 
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L
 typedef _Bool			bool;
+#endif
 
 typedef __kernel_uid32_t	uid_t;
 typedef __kernel_gid32_t	gid_t;
Signature · 1 line
2.51.0