[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bison uses two different 'bool' flavors
From: |
Akim Demaille |
Subject: |
Re: Bison uses two different 'bool' flavors |
Date: |
22 Oct 2002 14:33:53 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter) |
Akim:
| Paul:
| | +AC_DEFUN([AC_HEADER_STDBOOL],
|
| How about installing this guy in Autoconf :)
I'm installing the following patch Paul. There are a few changes:
AC_TRY_RUN is considered obsolete, and I believe we don't want to
indent the #directives. I also trust #error is supported by any
compiler (I have never seen proofs of the opposite, just vague
memories) and certainly by compilers who are expected to have
stdbool.h.
Nevertheless I have a question: is it normal that it fails on my
machine?
| configure:2029: checking for stdbool.h that conforms to C99
| configure:2079: gcc -c -g -O2 conftest.c >&5
| configure:2038: #error bool is not defined
| configure:2050: #error true is not 1
| configure:2082: $? = 1
| configure: failed program was:
| #line 2034 "configure"
| #include "confdefs.h"
|
| #include <stdbool.h>
| #ifndef bool
| # error bool is not defined
| #endif
| #ifndef false
| # error false is not defined
| #endif
| #if false
| # error false is not 0
| #endif
| #ifndef true
| # error false is not defined
| #endif
| #if true != 1
| # error true is not 1
| #endif
| #ifndef __bool_true_false_are_defined
| # error __bool_true_false_are_defined is not defined
| #endif
|
| struct s { _Bool s: 1; _Bool t; } s;
|
| char a[true == 1 ? 1 : -1];
| char b[false == 0 ? 1 : -1];
| char c[__bool_true_false_are_defined == 1 ? 1 : -1];
| char d[(bool) -0.5 == true ? 1 : -1];
| bool e = &s;
| char f[(_Bool) -0.0 == false ? 1 : -1];
| char g[true];
| char h[sizeof (_Bool)];
| char i[sizeof s.t];
|
| int
| main ()
| {
| return !a + !b + !c + !d + !e + !f + !g + !h + !i;
| ;
| return 0;
| }
| configure:2098: result: no
Here is the way it fails on Bison, i.e., *without* the #error:
| configure:4322: checking for stdbool.h that conforms to C99
| configure:4372: gcc -c -g -O2 conftest.c >&5
| configure:4331: parse error before string constant
| configure:4349: warning: data definition has no type or storage class
| configure:4349: warning: data definition has no type or storage class
| configure:4354: size of array `d' is negative
| configure:4355: incompatible types in initialization
| configure:4355: initializer element is not constant
| configure:4356: `_Bool' undeclared here (not in a function)
| configure:4358: `_Bool' undeclared here (not in a function)
| configure:4359: request for member `t' in something not a structure or union
| configure:4375: $? = 1
| configure: failed program was:
| #line 4327 "configure"
| #include "confdefs.h"
|
| #include <stdbool.h>
| #ifndef bool
| "error: bool is not defined"
| #endif
| #ifndef false
| "error: false is not defined"
| #endif
| #if false
| "error: false is not 0"
| #endif
| #ifndef true
| "error: false is not defined"
| #endif
| #if true != 1
| "error: true is not 1"
| #endif
| #ifndef __bool_true_false_are_defined
| "error: __bool_true_false_are_defined is not defined"
| #endif
|
| struct s { _Bool s: 1; _Bool t; } s;
|
| char a[true == 1 ? 1 : -1];
| char b[false == 0 ? 1 : -1];
| char c[__bool_true_false_are_defined == 1 ? 1 : -1];
| char d[(bool) -0.5 == true ? 1 : -1];
| bool e = &s;
| char f[(_Bool) -0.0 == false ? 1 : -1];
| char g[true];
| char h[sizeof (_Bool)];
| char i[sizeof s.t];
|
| int
| main ()
| {
| return !a + !b + !c + !d + !e + !f + !g + !h + !i;
| ;
| return 0;
| }
| configure:4391: result: no
|
Anyway, here is the patch:
Index: ChangeLog
from Akim Demaille <address@hidden>
* lib/autoconf/headers.m4 (AC_HEADER_STDBOOL): New, based on CVS
Bison, by Paul Eggert.
* doc/autoconf.texi (Particular Headers): Document it.
Index: NEWS
===================================================================
RCS file: /cvsroot/autoconf/autoconf/NEWS,v
retrieving revision 1.269
diff -u -u -r1.269 NEWS
--- NEWS 22 Oct 2002 12:18:46 -0000 1.269
+++ NEWS 22 Oct 2002 12:32:37 -0000
@@ -11,7 +11,7 @@
** Macros
- New macros
- AC_FUNC_MBRTOWC
+ AC_FUNC_MBRTOWC, AC_HEADER_STDBOOL.
- Obsoleted
Obsoleted macros are kept for Autoconf backward compatibility, but
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.691
diff -u -u -r1.691 autoconf.texi
--- doc/autoconf.texi 22 Oct 2002 12:13:21 -0000 1.691
+++ doc/autoconf.texi 22 Oct 2002 12:32:40 -0000
@@ -4281,6 +4281,22 @@
Amdahl UTS and Motorola System V/88.
@end defmac
address@hidden AC_HEADER_STDBOOL
address@hidden HEADER_STDBOOL
address@hidden HAVE_STDBOOL_H
+If @file{stdbool.h} exists and is conformant to C99, define
address@hidden to 1. Your @file{system.h} should contain the
+following code:
+
address@hidden
+#if HAVE_STDBOOL_H
+# include <stdbool.h>
+#else
+typedef enum {false = 0, true = 1} bool;
+#endif
address@hidden verbatim
address@hidden defmac
+
@defmac AC_HEADER_STDC
@acindex HEADER_STDC
Index: lib/autoconf/headers.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/headers.m4,v
retrieving revision 1.24
diff -u -u -r1.24 headers.m4
--- lib/autoconf/headers.m4 22 Oct 2002 12:02:08 -0000 1.24
+++ lib/autoconf/headers.m4 22 Oct 2002 12:32:40 -0000
@@ -487,6 +487,58 @@
])# AC_HEADER_STAT
+# AC_HEADER_STDBOOL
+# -----------------
+# Check for stdbool.h that conforms to C99.
+AN_IDENTIFIER([bool], [AC_HEADER_STDBOOL])
+AN_IDENTIFIER([true], [AC_HEADER_STDBOOL])
+AN_IDENTIFIER([false],[AC_HEADER_STDBOOL])
+AC_DEFUN([AC_HEADER_STDBOOL],
+[AC_CACHE_CHECK([for stdbool.h that conforms to C99],
+ [ac_cv_header_stdbool_h],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+ [[
+#include <stdbool.h>
+#ifndef bool
+# error bool is not defined
+#endif
+#ifndef false
+# error false is not defined
+#endif
+#if false
+# error false is not 0
+#endif
+#ifndef true
+# error false is not defined
+#endif
+#if true != 1
+# error true is not 1
+#endif
+#ifndef __bool_true_false_are_defined
+# error __bool_true_false_are_defined is not defined
+#endif
+
+ struct s { _Bool s: 1; _Bool t; } s;
+
+ char a[true == 1 ? 1 : -1];
+ char b[false == 0 ? 1 : -1];
+ char c[__bool_true_false_are_defined == 1 ? 1 : -1];
+ char d[(bool) -0.5 == true ? 1 : -1];
+ bool e = &s;
+ char f[(_Bool) -0.0 == false ? 1 : -1];
+ char g[true];
+ char h[sizeof (_Bool)];
+ char i[sizeof s.t];
+ ]],
+ [[ return !a + !b + !c + !d + !e + !f + !g + !h + !i; ]])],
+ [ac_cv_header_stdbool_h=yes],
+ [ac_cv_header_stdbool_h=no])])
+if test $ac_cv_header_stdbool_h = yes; then
+ AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
+fi
+])# AC_HEADER_STDBOOL
+
+
# AC_HEADER_STDC
# --------------
# FIXME: I find this list very strange. It comes from the original
Index: lib/autoscan/autoscan.list
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoscan/autoscan.list,v
retrieving revision 1.6
diff -u -u -r1.6 autoscan.list
--- lib/autoscan/autoscan.list 11 Oct 2002 12:17:52 -0000 1.6
+++ lib/autoscan/autoscan.list 22 Oct 2002 12:32:40 -0000
@@ -247,7 +247,9 @@
identifier: S_ISLNK AC_HEADER_STAT
identifier: S_ISREG AC_HEADER_STAT
identifier: S_ISSOCK AC_HEADER_STAT
+identifier: bool AC_HEADER_STDBOOL
identifier: const AC_C_CONST
+identifier: false AC_HEADER_STDBOOL
identifier: gid_t AC_TYPE_UID_T
identifier: inline AC_C_INLINE
identifier: mode_t AC_TYPE_MODE_T
@@ -263,6 +265,7 @@
identifier: timeval AC_HEADER_TIME
identifier: tm AC_STRUCT_TM
identifier: tm_zone AC_STRUCT_TIMEZONE
+identifier: true AC_HEADER_STDBOOL
identifier: uid_t AC_TYPE_UID_T
identifier: volatile AC_C_VOLATILE
makevar: AWK AC_PROG_AWK
- Re: Bison uses two different 'bool' flavors,
Akim Demaille <=