Define C23 header version macros

Joseph Myers josmyers@redhat.com
Thu Nov 20 21:48:48 GMT 2025


C23 defines library macros __STDC_VERSION_<header>_H__ to indicate
that a header has support for new / changed features from C23.  Now
that all the required library features are implemented in glibc,
define these macros.  I'm not sure this is sufficiently much of a
user-visible feature to be worth a mention in NEWS.

Tested for x86_64.

There are various optional C23 features we don't yet have, of which I
might look at the Annex H ones (floating-point encoding conversion
functions and _Float16 functions) next.

* Optional time bases TIME_MONOTONIC, TIME_ACTIVE, TIME_THREAD_ACTIVE.
  See
  <https://sourceware.org/pipermail/libc-alpha/2023-June/149264.html>
  - we need to review / update that patch.  (I think patch 2/2,
  inventing new names for all the nonstandard CLOCK_* supported by the
  Linux kernel, is rather more dubious.)

* Updating conform/ tests for C23.

* Defining the rounding mode macro FE_TONEARESTFROMZERO for RISC-V (as
  far as I know, the only architecture supported by glibc that has
  hardware support for this rounding mode for binary floating point)
  and supporting it throughout glibc and its tests (especially the
  string/numeric conversions in both directions that explicitly handle
  each possible rounding mode, and various tests that do likewise).

* Annex H floating-point encoding conversion functions.  (It's not
  entirely clear which are optional even given support for Annex H;
  there's some wording applied inconsistently about only being
  required when non-arithmetic interchange formats are supported; see
  the comments I raised on the WG14 reflector on 23 Oct 2025.)

* _Float16 functions (and other header and testcase support for this
  type).

* Decimal floating-point support.

* Fully supporting __int128 and unsigned __int128 as integer types
  wider than intmax_t, as permitted by C23.  Would need doing in
  coordination with GCC, see GCC bug 113887 for more discussion of
  what's involved.

diff --git a/assert/assert.h b/assert/assert.h
index 839406ddf7..373a1142d8 100644
--- a/assert/assert.h
+++ b/assert/assert.h
@@ -34,6 +34,12 @@
 #define	_ASSERT_H	1
 #include <features.h>
 
+#if __GLIBC_USE (ISOC23)
+# ifndef __STDC_VERSION_ASSERT_H__
+#  define __STDC_VERSION_ASSERT_H__ 202311L
+# endif
+#endif
+
 #if defined __cplusplus && __GNUC_PREREQ (2,95)
 # define __ASSERT_VOID_CAST static_cast<void>
 #else
diff --git a/include/limits.h b/include/limits.h
index 6370ccd84d..baf79df609 100644
--- a/include/limits.h
+++ b/include/limits.h
@@ -180,7 +180,7 @@
 
 /* The macros for _Bool are not defined by GCC's <limits.h> before GCC
    11, or if _GNU_SOURCE is defined rather than enabling C23 support
-   with -std.  */
+   with -std; likewise for the version macro before GCC 13.  */
 #if __GLIBC_USE (ISOC23)
 # ifndef BOOL_MAX
 #  define BOOL_MAX 1
@@ -188,6 +188,9 @@
 # ifndef BOOL_WIDTH
 #  define BOOL_WIDTH 1
 # endif
+# ifndef __STDC_VERSION_LIMITS_H__
+#  define __STDC_VERSION_LIMITS_H__ 202311L
+# endif
 #endif
 
 #ifdef	__USE_POSIX
diff --git a/libio/stdio.h b/libio/stdio.h
index e0e70945fa..d5a44edfa6 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -29,6 +29,10 @@
 
 __BEGIN_DECLS
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_STDIO_H__ 202311L
+#endif
+
 #define __need_size_t
 #define __need_NULL
 #include <stddef.h>
diff --git a/math/complex.h b/math/complex.h
index c925c5c0a3..2c84953429 100644
--- a/math/complex.h
+++ b/math/complex.h
@@ -33,6 +33,10 @@
 
 __BEGIN_DECLS
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_COMPLEX_H__ 202311L
+#endif
+
 /* We might need to add support for more compilers here.  But since ISO
    C99 is out hopefully all maintained compilers will soon provide the data
    types `float complex' and `double complex'.  */
diff --git a/math/fenv.h b/math/fenv.h
index 07bbbf61df..8db719f687 100644
--- a/math/fenv.h
+++ b/math/fenv.h
@@ -65,6 +65,10 @@
 
 __BEGIN_DECLS
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_FENV_H__ 202311L
+#endif
+
 /* Floating-point exception handling.  */
 
 /* Clear the supported exceptions represented by EXCEPTS.  */
diff --git a/math/math.h b/math/math.h
index 5f1933a2f9..26cea186fc 100644
--- a/math/math.h
+++ b/math/math.h
@@ -39,6 +39,10 @@ __BEGIN_DECLS
 /* Gather machine dependent type support.  */
 #include <bits/floatn.h>
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_MATH_H__ 202311L
+#endif
+
 /* Value returned on overflow.  With IEEE 754 floating point, this is
    +Infinity, otherwise the largest representable positive value.  */
 #if __GNUC_PREREQ (3, 3)
diff --git a/math/tgmath.h b/math/tgmath.h
index 27a87c599d..89ee94e1f7 100644
--- a/math/tgmath.h
+++ b/math/tgmath.h
@@ -30,6 +30,10 @@
 #include <math.h>
 #include <complex.h>
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_TGMATH_H__ 202311L
+#endif
+
 
 /* There are two variant implementations of type-generic macros in
    this file: one for GCC 8 and later, using __builtin_tgmath and
diff --git a/setjmp/setjmp.h b/setjmp/setjmp.h
index 7a4760e291..f232ddcd6b 100644
--- a/setjmp/setjmp.h
+++ b/setjmp/setjmp.h
@@ -26,6 +26,10 @@
 
 __BEGIN_DECLS
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_SETJMP_H__ 202311L
+#endif
+
 #include <bits/setjmp.h>		/* Get `__jmp_buf'.  */
 #include <bits/types/struct___jmp_buf_tag.h>
 
diff --git a/stdlib/inttypes.h b/stdlib/inttypes.h
index 6b64917b54..13cb7fae36 100644
--- a/stdlib/inttypes.h
+++ b/stdlib/inttypes.h
@@ -23,6 +23,11 @@
 #define _INTTYPES_H	1
 
 #include <features.h>
+
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_INTTYPES_H__ 202311L
+#endif
+
 /* Get the type definitions.  */
 #include <stdint.h>
 
diff --git a/stdlib/stdint.h b/stdlib/stdint.h
index 302230914c..814718a366 100644
--- a/stdlib/stdint.h
+++ b/stdlib/stdint.h
@@ -28,6 +28,10 @@
 #include <bits/wchar.h>
 #include <bits/wordsize.h>
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_STDINT_H__ 202311L
+#endif
+
 /* Exact integral types.  */
 
 /* Signed.  */
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index 4a79c612de..a1ea003658 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -35,6 +35,10 @@ __BEGIN_DECLS
 
 #define	_STDLIB_H	1
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_STDLIB_H__ 202311L
+#endif
+
 #if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
 /* XPG requires a few symbols from <sys/wait.h> being defined.  */
 # include <bits/waitflags.h>
diff --git a/string/string.h b/string/string.h
index 1dc5995c17..b8747506db 100644
--- a/string/string.h
+++ b/string/string.h
@@ -27,6 +27,10 @@
 
 __BEGIN_DECLS
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_STRING_H__ 202311L
+#endif
+
 /* Get size_t and NULL from <stddef.h>.  */
 #define	__need_size_t
 #define	__need_NULL
diff --git a/time/time.h b/time/time.h
index 4913508d86..ca4f2828de 100644
--- a/time/time.h
+++ b/time/time.h
@@ -28,6 +28,10 @@
 #define __need_NULL
 #include <stddef.h>
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_TIME_H__ 202311L
+#endif
+
 /* This defines CLOCKS_PER_SEC, which is the number of processor clock
    ticks per second, and possibly a number of other constants.   */
 #include <bits/time.h>
diff --git a/wcsmbs/uchar.h b/wcsmbs/uchar.h
index 335bfa343d..c774b1cd34 100644
--- a/wcsmbs/uchar.h
+++ b/wcsmbs/uchar.h
@@ -31,6 +31,10 @@
 #include <bits/types.h>
 #include <bits/types/mbstate_t.h>
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_UCHAR_H__ 202311L
+#endif
+
 /* Declare the C23 char8_t typedef in C23 modes, but only if the C++
   __cpp_char8_t feature test macro is not defined.  */
 #if __GLIBC_USE (ISOC23) && !defined __cpp_char8_t
diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h
index 19f71f90cf..e7170d2173 100644
--- a/wcsmbs/wchar.h
+++ b/wcsmbs/wchar.h
@@ -60,6 +60,10 @@ typedef __gnuc_va_list va_list;
 # include <bits/types/locale_t.h>
 #endif
 
+#if __GLIBC_USE (ISOC23)
+# define __STDC_VERSION_WCHAR_H__ 202311L
+#endif
+
 /* Tell the caller that we provide correct C++ prototypes.  */
 #if defined __cplusplus && __GNUC_PREREQ (4, 4)
 # define __CORRECT_ISO_CPP_WCHAR_H_PROTO

-- 
Joseph S. Myers
josmyers@redhat.com



More information about the Libc-alpha mailing list