annotate m4/stdbool.m4 @ 445:7899511b2102 3.0

Added tag 3.0.1 for changeset a8934dfba400
author lost@l-w.ca
date Sat, 30 Oct 2010 15:22:55 -0600
parents b8bf63962a99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
434
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1 # Check for stdbool.h that conforms to C99.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
2
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
3 dnl Copyright (C) 2002-2006, 2009-2010 Free Software Foundation, Inc.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
4 dnl This file is free software; the Free Software Foundation
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
5 dnl gives unlimited permission to copy and/or distribute it,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
6 dnl with or without modifications, as long as this notice is preserved.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
7
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
8 # Prepare for substituting <stdbool.h> if it is not supported.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
9
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
10 AC_DEFUN([AM_STDBOOL_H],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
11 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
12 AC_REQUIRE([AC_HEADER_STDBOOL])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
13
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
14 # Define two additional variables used in the Makefile substitution.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
15
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
16 if test "$ac_cv_header_stdbool_h" = yes; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
17 STDBOOL_H=''
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
18 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
19 STDBOOL_H='stdbool.h'
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
20 fi
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
21 AC_SUBST([STDBOOL_H])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
22
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
23 if test "$ac_cv_type__Bool" = yes; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
24 HAVE__BOOL=1
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
25 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
26 HAVE__BOOL=0
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
27 fi
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
28 AC_SUBST([HAVE__BOOL])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
29 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
30
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
31 # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
32 AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
33
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
34 # This macro is only needed in autoconf <= 2.59. Newer versions of autoconf
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
35 # have this macro built-in.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
36
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
37 AC_DEFUN([AC_HEADER_STDBOOL],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
38 [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
39 [ac_cv_header_stdbool_h],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
40 [AC_TRY_COMPILE(
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
41 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
42 #include <stdbool.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
43 #ifndef bool
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
44 "error: bool is not defined"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
45 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
46 #ifndef false
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
47 "error: false is not defined"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
48 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
49 #if false
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
50 "error: false is not 0"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
51 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
52 #ifndef true
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
53 "error: true is not defined"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
54 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
55 #if true != 1
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
56 "error: true is not 1"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
57 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
58 #ifndef __bool_true_false_are_defined
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
59 "error: __bool_true_false_are_defined is not defined"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
60 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
61
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
62 struct s { _Bool s: 1; _Bool t; } s;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
63
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
64 char a[true == 1 ? 1 : -1];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
65 char b[false == 0 ? 1 : -1];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
66 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
67 char d[(bool) 0.5 == true ? 1 : -1];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
68 bool e = &s;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
69 char f[(_Bool) 0.0 == false ? 1 : -1];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
70 char g[true];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
71 char h[sizeof (_Bool)];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
72 char i[sizeof s.t];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
73 enum { j = false, k = true, l = false * true, m = true * 256 };
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
74 _Bool n[m];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
75 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
76 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
77 #if defined __xlc__ || defined __GNUC__
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
78 /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
79 reported by James Lemley on 2005-10-05; see
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
80 http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
81 This test is not quite right, since xlc is allowed to
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
82 reject this program, as the initializer for xlcbug is
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
83 not one of the forms that C requires support for.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
84 However, doing the test right would require a run-time
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
85 test, and that would make cross-compilation harder.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
86 Let us hope that IBM fixes the xlc bug, and also adds
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
87 support for this kind of constant expression. In the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
88 meantime, this test will reject xlc, which is OK, since
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
89 our stdbool.h substitute should suffice. We also test
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
90 this with GCC, where it should work, to detect more
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
91 quickly whether someone messes up the test in the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
92 future. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
93 char digs[] = "0123456789";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
94 int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
95 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
96 /* Catch a bug in an HP-UX C compiler. See
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
97 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
98 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
99 */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
100 _Bool q = true;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
101 _Bool *pq = &q;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
102 ],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
103 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
104 *pq |= q;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
105 *pq |= ! q;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
106 /* Refer to every declared value, to avoid compiler optimizations. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
107 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
108 + !m + !n + !o + !p + !q + !pq);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
109 ],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
110 [ac_cv_header_stdbool_h=yes],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
111 [ac_cv_header_stdbool_h=no])])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
112 AC_CHECK_TYPES([_Bool])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
113 if test $ac_cv_header_stdbool_h = yes; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
114 AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to C99.])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
115 fi])