2 dnl Copyright (C) 2001-2018 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl From Paul Eggert and Bruno Haible.
8 dnl Test whether <stdint.h> is supported or must be substituted.
10 AC_DEFUN_ONCE([gl_STDINT_H],
13 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
15 AC_REQUIRE([gl_LIMITS_H])
16 AC_REQUIRE([gt_TYPE_WINT_T])
18 dnl Check for long long int and unsigned long long int.
19 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
20 if test $ac_cv_type_long_long_int = yes; then
25 AC_SUBST([HAVE_LONG_LONG_INT])
26 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
27 if test $ac_cv_type_unsigned_long_long_int = yes; then
28 HAVE_UNSIGNED_LONG_LONG_INT=1
30 HAVE_UNSIGNED_LONG_LONG_INT=0
32 AC_SUBST([HAVE_UNSIGNED_LONG_LONG_INT])
34 dnl Check for <wchar.h>, in the same way as gl_WCHAR_H does.
35 AC_CHECK_HEADERS_ONCE([wchar.h])
36 if test $ac_cv_header_wchar_h = yes; then
41 AC_SUBST([HAVE_WCHAR_H])
43 dnl Check for <inttypes.h>.
44 dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h.
45 if test $ac_cv_header_inttypes_h = yes; then
50 AC_SUBST([HAVE_INTTYPES_H])
52 dnl Check for <sys/types.h>.
53 dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h.
54 if test $ac_cv_header_sys_types_h = yes; then
59 AC_SUBST([HAVE_SYS_TYPES_H])
61 gl_CHECK_NEXT_HEADERS([stdint.h])
62 if test $ac_cv_header_stdint_h = yes; then
67 AC_SUBST([HAVE_STDINT_H])
69 dnl Now see whether we need a substitute <stdint.h>.
70 if test $ac_cv_header_stdint_h = yes; then
71 AC_CACHE_CHECK([whether stdint.h conforms to C99],
72 [gl_cv_header_working_stdint_h],
73 [gl_cv_header_working_stdint_h=no
76 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
77 #define __STDC_CONSTANT_MACROS 1
78 #define __STDC_LIMIT_MACROS 1
80 /* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>. */
81 #if !(defined WCHAR_MIN && defined WCHAR_MAX)
82 #error "WCHAR_MIN, WCHAR_MAX not defined in <stdint.h>"
89 int8_t a1min = INT8_MIN;
92 int16_t a2 = INT16_MAX;
93 int16_t a2min = INT16_MIN;
96 int32_t a3 = INT32_MAX;
97 int32_t a3min = INT32_MIN;
100 int64_t a4 = INT64_MAX;
101 int64_t a4min = INT64_MIN;
104 uint8_t b1 = UINT8_MAX;
106 typedef int b1[(unsigned char) -1 != 255 ? 1 : -1];
109 uint16_t b2 = UINT16_MAX;
112 uint32_t b3 = UINT32_MAX;
115 uint64_t b4 = UINT64_MAX;
117 int_least8_t c1 = INT8_C (0x7f);
118 int_least8_t c1max = INT_LEAST8_MAX;
119 int_least8_t c1min = INT_LEAST8_MIN;
120 int_least16_t c2 = INT16_C (0x7fff);
121 int_least16_t c2max = INT_LEAST16_MAX;
122 int_least16_t c2min = INT_LEAST16_MIN;
123 int_least32_t c3 = INT32_C (0x7fffffff);
124 int_least32_t c3max = INT_LEAST32_MAX;
125 int_least32_t c3min = INT_LEAST32_MIN;
126 int_least64_t c4 = INT64_C (0x7fffffffffffffff);
127 int_least64_t c4max = INT_LEAST64_MAX;
128 int_least64_t c4min = INT_LEAST64_MIN;
129 uint_least8_t d1 = UINT8_C (0xff);
130 uint_least8_t d1max = UINT_LEAST8_MAX;
131 uint_least16_t d2 = UINT16_C (0xffff);
132 uint_least16_t d2max = UINT_LEAST16_MAX;
133 uint_least32_t d3 = UINT32_C (0xffffffff);
134 uint_least32_t d3max = UINT_LEAST32_MAX;
135 uint_least64_t d4 = UINT64_C (0xffffffffffffffff);
136 uint_least64_t d4max = UINT_LEAST64_MAX;
137 int_fast8_t e1 = INT_FAST8_MAX;
138 int_fast8_t e1min = INT_FAST8_MIN;
139 int_fast16_t e2 = INT_FAST16_MAX;
140 int_fast16_t e2min = INT_FAST16_MIN;
141 int_fast32_t e3 = INT_FAST32_MAX;
142 int_fast32_t e3min = INT_FAST32_MIN;
143 int_fast64_t e4 = INT_FAST64_MAX;
144 int_fast64_t e4min = INT_FAST64_MIN;
145 uint_fast8_t f1 = UINT_FAST8_MAX;
146 uint_fast16_t f2 = UINT_FAST16_MAX;
147 uint_fast32_t f3 = UINT_FAST32_MAX;
148 uint_fast64_t f4 = UINT_FAST64_MAX;
150 intptr_t g = INTPTR_MAX;
151 intptr_t gmin = INTPTR_MIN;
154 uintptr_t h = UINTPTR_MAX;
156 intmax_t i = INTMAX_MAX;
157 uintmax_t j = UINTMAX_MAX;
159 /* Check that SIZE_MAX has the correct type, if possible. */
160 #if 201112 <= __STDC_VERSION__
161 int k = _Generic (SIZE_MAX, size_t: 0);
162 #elif (2 <= __GNUC__ || defined __IBM__TYPEOF__ \
163 || (0x5110 <= __SUNPRO_C && !__STDC__))
165 extern __typeof__ (SIZE_MAX) k;
168 #include <limits.h> /* for CHAR_BIT */
169 #define TYPE_MINIMUM(t) \
170 ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ TYPE_MAXIMUM (t)))
171 #define TYPE_MAXIMUM(t) \
172 ((t) ((t) 0 < (t) -1 \
174 : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
177 PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t)
178 && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t)
180 /* Detect bug in FreeBSD 6.0 / ia64. */
181 int check_SIG_ATOMIC:
182 SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t)
183 && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t)
185 int check_SIZE: SIZE_MAX == TYPE_MAXIMUM (size_t) ? 1 : -1;
187 WCHAR_MIN == TYPE_MINIMUM (wchar_t)
188 && WCHAR_MAX == TYPE_MAXIMUM (wchar_t)
190 /* Detect bug in mingw. */
192 WINT_MIN == TYPE_MINIMUM (wint_t)
193 && WINT_MAX == TYPE_MAXIMUM (wint_t)
196 /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */
198 (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1;
200 (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1;
202 /* Detect bugs in OpenBSD 3.9 stdint.h. */
204 int check_uint8: (uint8_t) -1 == UINT8_MAX ? 1 : -1;
207 int check_uint16: (uint16_t) -1 == UINT16_MAX ? 1 : -1;
210 int check_uint32: (uint32_t) -1 == UINT32_MAX ? 1 : -1;
213 int check_uint64: (uint64_t) -1 == UINT64_MAX ? 1 : -1;
215 int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1;
216 int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1;
217 int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1;
218 int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1;
219 int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1;
220 int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1;
221 int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1;
222 int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1;
223 int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1;
224 int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1;
225 int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1;
228 [dnl Determine whether the various *_MIN, *_MAX macros are usable
229 dnl in preprocessor expression. We could do it by compiling a test
230 dnl program for each of these macros. It is faster to run a program
231 dnl that inspects the macro expansion.
232 dnl This detects a bug on HP-UX 11.23/ia64.
235 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
236 #define __STDC_CONSTANT_MACROS 1
237 #define __STDC_LIMIT_MACROS 1
244 #define MVAL(macro) MVAL1(macro)
245 #define MVAL1(expression) #expression
246 static const char *macro_values[] =
276 for (mv = macro_values; *mv != NULL; mv++)
278 const char *value = *mv;
279 /* Test whether it looks like a cast expression. */
280 if (strncmp (value, "((unsigned int)"/*)*/, 15) == 0
281 || strncmp (value, "((unsigned short)"/*)*/, 17) == 0
282 || strncmp (value, "((unsigned char)"/*)*/, 16) == 0
283 || strncmp (value, "((int)"/*)*/, 6) == 0
284 || strncmp (value, "((signed short)"/*)*/, 15) == 0
285 || strncmp (value, "((signed char)"/*)*/, 14) == 0)
286 return mv - macro_values + 1;
290 [gl_cv_header_working_stdint_h=yes],
293 # Guess yes on native Windows.
294 mingw*) gl_cv_header_working_stdint_h="guessing yes" ;;
295 # In general, assume it works.
296 *) gl_cv_header_working_stdint_h="guessing yes" ;;
305 HAVE_SYS_INTTYPES_H=0
307 case "$gl_cv_header_working_stdint_h" in
310 dnl Now see whether the system <stdint.h> works without
311 dnl __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined.
312 AC_CACHE_CHECK([whether stdint.h predates C++11],
313 [gl_cv_header_stdint_predates_cxx11_h],
314 [gl_cv_header_stdint_predates_cxx11_h=yes
317 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
322 intmax_t im = INTMAX_MAX;
323 int32_t i32 = INT32_C (0x7fffffff);
325 [gl_cv_header_stdint_predates_cxx11_h=no])])
327 if test "$gl_cv_header_stdint_predates_cxx11_h" = yes; then
328 AC_DEFINE([__STDC_CONSTANT_MACROS], [1],
329 [Define to 1 if the system <stdint.h> predates C++11.])
330 AC_DEFINE([__STDC_LIMIT_MACROS], [1],
331 [Define to 1 if the system <stdint.h> predates C++11.])
333 AC_CACHE_CHECK([whether stdint.h has UINTMAX_WIDTH etc.],
334 [gl_cv_header_stdint_width],
335 [gl_cv_header_stdint_width=no
338 /* Work if build is not clean. */
339 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1
340 #ifndef __STDC_WANT_IEC_60559_BFP_EXT__
341 #define __STDC_WANT_IEC_60559_BFP_EXT__ 1
345 int iw = UINTMAX_WIDTH;
347 [gl_cv_header_stdint_width=yes])])
348 if test "$gl_cv_header_stdint_width" = yes; then
353 dnl Check for <sys/inttypes.h>, and for
354 dnl <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5).
355 AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h])
356 if test $ac_cv_header_sys_inttypes_h = yes; then
357 HAVE_SYS_INTTYPES_H=1
359 if test $ac_cv_header_sys_bitypes_h = yes; then
362 gl_STDINT_TYPE_PROPERTIES
366 dnl The substitute stdint.h needs the substitute limit.h's _GL_INTEGER_WIDTH.
368 AM_CONDITIONAL([GL_GENERATE_LIMITS_H], [test -n "$LIMITS_H"])
370 AC_SUBST([HAVE_C99_STDINT_H])
371 AC_SUBST([HAVE_SYS_BITYPES_H])
372 AC_SUBST([HAVE_SYS_INTTYPES_H])
374 AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"])
377 dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES)
378 dnl Determine the size of each of the given types in bits.
379 AC_DEFUN([gl_STDINT_BITSIZEOF],
381 dnl Use a shell loop, to avoid bloating configure, and
382 dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
384 dnl - extra AC_SUBST calls, so that the right substitutions are made.
385 m4_foreach_w([gltype], [$1],
386 [AH_TEMPLATE([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]),
387 [Define to the number of bits in type ']gltype['.])])
388 for gltype in $1 ; do
389 AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}],
390 [AC_COMPUTE_INT([result], [sizeof ($gltype) * CHAR_BIT],
392 #include <limits.h>], [result=unknown])
393 eval gl_cv_bitsizeof_${gltype}=\$result
395 eval result=\$gl_cv_bitsizeof_${gltype}
396 if test $result = unknown; then
397 dnl Use a nonempty default, because some compilers, such as IRIX 5 cc,
398 dnl do a syntax check even on unused #if conditions and give an error
399 dnl on valid C code like this:
406 GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
407 AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result])
408 eval BITSIZEOF_${GLTYPE}=\$result
410 m4_foreach_w([gltype], [$1],
411 [AC_SUBST([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))])
414 dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES)
415 dnl Determine the signedness of each of the given types.
416 dnl Define HAVE_SIGNED_TYPE if type is signed.
417 AC_DEFUN([gl_CHECK_TYPES_SIGNED],
419 dnl Use a shell loop, to avoid bloating configure, and
420 dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
422 dnl - extra AC_SUBST calls, so that the right substitutions are made.
423 m4_foreach_w([gltype], [$1],
424 [AH_TEMPLATE([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]),
425 [Define to 1 if ']gltype[' is a signed integer type.])])
426 for gltype in $1 ; do
427 AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed],
429 [AC_LANG_PROGRAM([$2[
430 int verify[2 * (($gltype) -1 < ($gltype) 0) - 1];]])],
431 result=yes, result=no)
432 eval gl_cv_type_${gltype}_signed=\$result
434 eval result=\$gl_cv_type_${gltype}_signed
435 GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
436 if test "$result" = yes; then
437 AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], [1])
438 eval HAVE_SIGNED_${GLTYPE}=1
440 eval HAVE_SIGNED_${GLTYPE}=0
443 m4_foreach_w([gltype], [$1],
444 [AC_SUBST([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))])
447 dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES)
448 dnl Determine the suffix to use for integer constants of the given types.
449 dnl Define t_SUFFIX for each such type.
450 AC_DEFUN([gl_INTEGER_TYPE_SUFFIX],
452 dnl Use a shell loop, to avoid bloating configure, and
453 dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
455 dnl - extra AC_SUBST calls, so that the right substitutions are made.
456 m4_foreach_w([gltype], [$1],
457 [AH_TEMPLATE(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX],
458 [Define to l, ll, u, ul, ull, etc., as suitable for
459 constants of type ']gltype['.])])
460 for gltype in $1 ; do
461 AC_CACHE_CHECK([for $gltype integer literal suffix],
462 [gl_cv_type_${gltype}_suffix],
463 [eval gl_cv_type_${gltype}_suffix=no
464 eval result=\$gl_cv_type_${gltype}_signed
465 if test "$result" = yes; then
470 for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do
473 l) gltype1='long int';;
474 ll) gltype1='long long int';;
475 i64) gltype1='__int64';;
476 u) gltype1='unsigned int';;
477 ul) gltype1='unsigned long int';;
478 ull) gltype1='unsigned long long int';;
479 ui64)gltype1='unsigned __int64';;
482 [AC_LANG_PROGRAM([$2[
484 extern $gltype1 foo;]])],
485 [eval gl_cv_type_${gltype}_suffix=\$glsuf])
486 eval result=\$gl_cv_type_${gltype}_suffix
487 test "$result" != no && break
489 GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
490 eval result=\$gl_cv_type_${gltype}_suffix
491 test "$result" = no && result=
492 eval ${GLTYPE}_SUFFIX=\$result
493 AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], [$result])
495 m4_foreach_w([gltype], [$1],
496 [AC_SUBST(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])])
499 dnl gl_STDINT_INCLUDES
500 AC_DEFUN([gl_STDINT_INCLUDES],
502 /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
503 included before <wchar.h>. */
513 dnl gl_STDINT_TYPE_PROPERTIES
514 dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t
515 dnl of interest to stdint.in.h.
516 AC_DEFUN([gl_STDINT_TYPE_PROPERTIES],
518 AC_REQUIRE([gl_MULTIARCH])
519 if test $APPLE_UNIVERSAL_BUILD = 0; then
520 gl_STDINT_BITSIZEOF([ptrdiff_t size_t],
521 [gl_STDINT_INCLUDES])
523 gl_STDINT_BITSIZEOF([sig_atomic_t wchar_t wint_t],
524 [gl_STDINT_INCLUDES])
525 gl_CHECK_TYPES_SIGNED([sig_atomic_t wchar_t wint_t],
526 [gl_STDINT_INCLUDES])
527 gl_cv_type_ptrdiff_t_signed=yes
528 gl_cv_type_size_t_signed=no
529 if test $APPLE_UNIVERSAL_BUILD = 0; then
530 gl_INTEGER_TYPE_SUFFIX([ptrdiff_t size_t],
531 [gl_STDINT_INCLUDES])
533 gl_INTEGER_TYPE_SUFFIX([sig_atomic_t wchar_t wint_t],
534 [gl_STDINT_INCLUDES])
536 dnl If wint_t is smaller than 'int', it cannot satisfy the ISO C 99
537 dnl requirement that wint_t is "unchanged by default argument promotions".
538 dnl In this case gnulib's <wchar.h> and <wctype.h> override wint_t.
539 dnl Set the variable BITSIZEOF_WINT_T accordingly.
540 if test $GNULIB_OVERRIDES_WINT_T = 1; then
545 dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
546 dnl Remove this when we can assume autoconf >= 2.61.
547 m4_ifdef([AC_COMPUTE_INT], [], [
548 AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])