]> git.saurik.com Git - bison.git/blob - m4/stdbool.m4
Sync with gnulib.
[bison.git] / m4 / stdbool.m4
1 # Check for stdbool.h that conforms to C99.
2
3 # Copyright (C) 2002 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 # 02111-1307, USA.
19
20 AC_DEFUN([AC_HEADER_STDBOOL],
21 [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
22 [ac_cv_header_stdbool_h],
23 [AC_TRY_COMPILE(
24 [
25 #include <stdbool.h>
26 #ifndef bool
27 "error: bool is not defined"
28 #endif
29 #ifndef false
30 "error: false is not defined"
31 #endif
32 #if false
33 "error: false is not 0"
34 #endif
35 #ifndef true
36 "error: false is not defined"
37 #endif
38 #if true != 1
39 "error: true is not 1"
40 #endif
41 #ifndef __bool_true_false_are_defined
42 "error: __bool_true_false_are_defined is not defined"
43 #endif
44
45 struct s { _Bool s: 1; _Bool t; } s;
46
47 char a[true == 1 ? 1 : -1];
48 char b[false == 0 ? 1 : -1];
49 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
50 char d[(bool) -0.5 == true ? 1 : -1];
51 bool e = &s;
52 char f[(_Bool) -0.0 == false ? 1 : -1];
53 char g[true];
54 char h[sizeof (_Bool)];
55 char i[sizeof s.t];
56 ],
57 [ return !a + !b + !c + !d + !e + !f + !g + !h + !i; ],
58 [ac_cv_header_stdbool_h=yes],
59 [ac_cv_header_stdbool_h=no])])
60 if test $ac_cv_header_stdbool_h = yes; then
61 AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
62 fi])