[PATCH] Fix _GMP_H_HAVE_FILE detection on recent FreeBSD

Dimitry Andric dim at FreeBSD.org
Mon Aug 17 12:56:56 CEST 2026


On 17 Aug 2026, at 11:45, Marc Glisse <marc.glisse at inria.fr> wrote:
> 
> On Sun, 16 Aug 2026, Dimitry Andric wrote:
> 
>> In FreeBSD 16-CURRENT, some work has been ongoing to improve C23
>> support. As part of this, the FreeBSD stdio.h header has been changed to
>> longer define the macro _STDIO_H_, but to define the C23 standard macro
>> __STDC_VERSION_STDIO_H__ instead (with numeric value 202311L).
>> 
> [...]
>> 
>> For the FreeBSD port I have proposed a diff similar to the following.
> 
> Hello,
> 
> thanks for the report.
> I looked at C23 (or drafts from before/after), and it isn't clear to me
> how safe this is. As far as I understand (and I may be completely wrong),
> the guarantees are
> 
> * After including <stdio.h>, __STDC_VERSION_STDIO_H__ is defined to
> 202311L.

Yes, C23 has defined the following macros to signify that the
corresponding header files have been included:

  __STDC_VERSION_ASSERT_H__
  __STDC_VERSION_COMPLEX_H__
  __STDC_VERSION_FENV_H__
  __STDC_VERSION_FLOAT_H__
  __STDC_VERSION_INTTYPES_H__
  __STDC_VERSION_LIMITS_H__
  __STDC_VERSION_MATH_H__
  __STDC_VERSION_SETJMP_H__
  __STDC_VERSION_STDARG_H__
  __STDC_VERSION_STDATOMIC_H__
  __STDC_VERSION_STDBIT_H__
  __STDC_VERSION_STDCKDINT_H__
  __STDC_VERSION_STDDEF_H__
  __STDC_VERSION_STDINT_H__
  __STDC_VERSION_STDIO_H__
  __STDC_VERSION_STDLIB_H__
  __STDC_VERSION_STRING_H__
  __STDC_VERSION_TGMATH_H__
  __STDC_VERSION_TIME_H__
  __STDC_VERSION_UCHAR_H__
  __STDC_VERSION_WCHAR_H__

These are meant to replace the more fragile construct of figuring out
operating system specific macros used for a similar purpose.


> * If __STDC_VERSION_STDIO_H__ is 202311L, after including <stdio.h>, I'll
> have access to the C23 functionality.

In FreeBSD's case, the macro is defined unconditionally, but on other
systems it might be defined only for an explicit C23 language mode. For
example, glibc's stdio.h has:

#ifndef _STDIO_H
#define _STDIO_H        1

[...]

#if __GLIBC_USE (ISOC23)
# define __STDC_VERSION_STDIO_H__ 202311L
#endif

That said, if the macro _is_ defined, you can be sure that stdio.h was
included.


> I think an implementation is allowed to predefine __STDC_VERSION_STDIO_H__
> (and all the other similar macros) at startup, which would break this
> detection mechanism.

No, C23 explicitly says the macro is defined in stdio.h:

7.23 Input/output <stdio.h>

7.23.1 Introduction

1 The header <stdio.h> defines several macros, and declares three types
  and many functions for performing input and output.

2 The macro __STDC_VERSION_STDIO_H__ is an integer constant expression
  with a value equivalent to 202311L.


> Maybe we could reduce this risk by checking (defined
> (__STDC_VERSION_STDIO_H__) && defined (FOPEN_MAX)) or some other macro
> that stdio.h must provide?

There are also macros mentioned like:

NULL
_IOFBF
_IOLBF
_IONBF
BUFSIZ
EOF
FOPEN_MAX
FILENAME_MAX
_PRINTF_NAN_LEN_MAX
SEEK_CUR
SEEK_END
SEEK_SET
TMP_MAX

However, some of those are also defined in other standard headers. I
guess FOPEN_MAX might be the safest one?

-Dimitry



More information about the gmp-devel mailing list