Define C23 header version macros
Paul Eggert
eggert@cs.ucla.edu
Thu Nov 20 23:19:02 GMT 2025
Thanks for taking this on.
On 2025-11-20 13:48, Joseph Myers wrote:
> I'm not sure this is sufficiently much of a
> user-visible feature to be worth a mention in NEWS.
It's probably worth mentioning, in part to answer the questions posed in
my last comment at the end of this email.
> --- 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
assert.h is special because it can be multiply included with different
effects each time. So shouldn't this be done like other assert macros?
That is, define __STDC_VERSION_ASSERT_H__ without using the ifndef here,
and near the file's start if _ASSERT_H is already defined then #undef
__STDC_VERSION_ASSERT_H__ there. Although this sort of thing matters
only if the user fiddles with _ISOC23_SOURCE (which the user shouldn't
do of course) it would be a bit more robust in that fiddly situation.
Also, suppose the user compiles with --std=gnu2y? What should the value
of __STDC_VERSION_ASSERT_H__ be then? Perhaps it should be some
intermediate value like 202505L for the latest C2y draft that glibc
supports? Similarly for other __STDC_VERSION_*_H__ macros.
> +# ifndef __STDC_VERSION_LIMITS_H__
> +# define __STDC_VERSION_LIMITS_H__ 202311L
> +# endif
Why is the ifndef needed here, instead of a plain #define? Other places
don't have such an ifndef (except for assert.h, which is special because
it can be multiply included and which I discussed above).
> +#if __GLIBC_USE (ISOC23)
> +# define __STDC_VERSION_STDIO_H__ 202311L
> +#endif
Since glibc supports C23 <stdio.h>'s features regardless of whether
__GLIBC_USE (ISOC23) is true, how about doing this #define
unconditionally? Similarly for other __STDC_VERSION_*_H__ macros: the
idea is to define each such macro if the corresponding C23 features are
supported, regardless of whether __GLIBC_USE (ISOC23) is true.
Admittedly this could get a little tricky, e.g., <complex.h> needs at
least __USE_ISOC11 before it can define __STDC_VERSION_COMPLEX_H__ to
202311L, because macros like CMPLX are available only then.
More information about the Libc-alpha
mailing list