stdbool.m4 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Check for stdbool.h that conforms to C99.
  2. dnl Copyright (C) 2002-2006, 2009-2012 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.
  6. #serial 5
  7. # Prepare for substituting <stdbool.h> if it is not supported.
  8. AC_DEFUN([AM_STDBOOL_H],
  9. [
  10. AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
  11. # Define two additional variables used in the Makefile substitution.
  12. if test "$ac_cv_header_stdbool_h" = yes; then
  13. STDBOOL_H=''
  14. else
  15. STDBOOL_H='stdbool.h'
  16. fi
  17. AC_SUBST([STDBOOL_H])
  18. AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
  19. if test "$ac_cv_type__Bool" = yes; then
  20. HAVE__BOOL=1
  21. else
  22. HAVE__BOOL=0
  23. fi
  24. AC_SUBST([HAVE__BOOL])
  25. ])
  26. # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
  27. AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
  28. # This version of the macro is needed in autoconf <= 2.68.
  29. AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
  30. [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
  31. [ac_cv_header_stdbool_h],
  32. [AC_COMPILE_IFELSE(
  33. [AC_LANG_PROGRAM(
  34. [[
  35. #include <stdbool.h>
  36. #ifndef bool
  37. "error: bool is not defined"
  38. #endif
  39. #ifndef false
  40. "error: false is not defined"
  41. #endif
  42. #if false
  43. "error: false is not 0"
  44. #endif
  45. #ifndef true
  46. "error: true is not defined"
  47. #endif
  48. #if true != 1
  49. "error: true is not 1"
  50. #endif
  51. #ifndef __bool_true_false_are_defined
  52. "error: __bool_true_false_are_defined is not defined"
  53. #endif
  54. struct s { _Bool s: 1; _Bool t; } s;
  55. char a[true == 1 ? 1 : -1];
  56. char b[false == 0 ? 1 : -1];
  57. char c[__bool_true_false_are_defined == 1 ? 1 : -1];
  58. char d[(bool) 0.5 == true ? 1 : -1];
  59. /* See body of main program for 'e'. */
  60. char f[(_Bool) 0.0 == false ? 1 : -1];
  61. char g[true];
  62. char h[sizeof (_Bool)];
  63. char i[sizeof s.t];
  64. enum { j = false, k = true, l = false * true, m = true * 256 };
  65. /* The following fails for
  66. HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
  67. _Bool n[m];
  68. char o[sizeof n == m * sizeof n[0] ? 1 : -1];
  69. char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
  70. /* Catch a bug in an HP-UX C compiler. See
  71. http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
  72. http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
  73. */
  74. _Bool q = true;
  75. _Bool *pq = &q;
  76. ]],
  77. [[
  78. bool e = &s;
  79. *pq |= q;
  80. *pq |= ! q;
  81. /* Refer to every declared value, to avoid compiler optimizations. */
  82. return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
  83. + !m + !n + !o + !p + !q + !pq);
  84. ]])],
  85. [ac_cv_header_stdbool_h=yes],
  86. [ac_cv_header_stdbool_h=no])])
  87. AC_CHECK_TYPES([_Bool])
  88. ])