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