stdbool.m4 revision 1.1.1.1 1 # Check for stdbool.h that conforms to C99.
2
3 dnl Copyright (C) 2002-2004 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7
8 # Prepare for substituting <stdbool.h> if it is not supported.
9
10 AC_DEFUN([AM_STDBOOL_H],
11 [
12 AC_REQUIRE([AC_HEADER_STDBOOL])
13
14 # Define two additional variables used in the Makefile substitution.
15
16 if test "$ac_cv_header_stdbool_h" = yes; then
17 STDBOOL_H=''
18 else
19 STDBOOL_H='stdbool.h'
20 fi
21 AC_SUBST([STDBOOL_H])
22
23 if test "$ac_cv_type__Bool" = yes; then
24 HAVE__BOOL=1
25 else
26 HAVE__BOOL=0
27 fi
28 AC_SUBST([HAVE__BOOL])
29 ])
30
31 # This macro is only needed in autoconf <= 2.59. Newer versions of autoconf
32 # have this macro built-in.
33
34 AC_DEFUN([AC_HEADER_STDBOOL],
35 [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
36 [ac_cv_header_stdbool_h],
37 [AC_TRY_COMPILE(
38 [
39 #include <stdbool.h>
40 #ifndef bool
41 "error: bool is not defined"
42 #endif
43 #ifndef false
44 "error: false is not defined"
45 #endif
46 #if false
47 "error: false is not 0"
48 #endif
49 #ifndef true
50 "error: true is not defined"
51 #endif
52 #if true != 1
53 "error: true is not 1"
54 #endif
55 #ifndef __bool_true_false_are_defined
56 "error: __bool_true_false_are_defined is not defined"
57 #endif
58
59 struct s { _Bool s: 1; _Bool t; } s;
60
61 char a[true == 1 ? 1 : -1];
62 char b[false == 0 ? 1 : -1];
63 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
64 char d[(bool) -0.5 == true ? 1 : -1];
65 bool e = &s;
66 char f[(_Bool) -0.0 == false ? 1 : -1];
67 char g[true];
68 char h[sizeof (_Bool)];
69 char i[sizeof s.t];
70 enum { j = false, k = true, l = false * true, m = true * 256 };
71 _Bool n[m];
72 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
73 ],
74 [
75 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !j + !k + !l
76 + !m + !n + !o);
77 ],
78 [ac_cv_header_stdbool_h=yes],
79 [ac_cv_header_stdbool_h=no])])
80 AC_CHECK_TYPES([_Bool])
81 if test $ac_cv_header_stdbool_h = yes; then
82 AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
83 fi])
84