stdbool.m4 | stdbool.m4 | |||
---|---|---|---|---|
# Check for stdbool.h that conforms to C99. | # Check for stdbool.h that conforms to C99. | |||
dnl Copyright (C) 2002-2006, 2009-2010 Free Software Foundation, Inc. | dnl Copyright (C) 2002-2006, 2009-2014 Free Software Foundation, Inc. | |||
dnl This file is free software; the Free Software Foundation | dnl This file is free software; the Free Software Foundation | |||
dnl gives unlimited permission to copy and/or distribute it, | dnl gives unlimited permission to copy and/or distribute it, | |||
dnl with or without modifications, as long as this notice is preserved. | dnl with or without modifications, as long as this notice is preserved. | |||
#serial 5 | ||||
# Prepare for substituting <stdbool.h> if it is not supported. | # Prepare for substituting <stdbool.h> if it is not supported. | |||
AC_DEFUN([AM_STDBOOL_H], | AC_DEFUN([AM_STDBOOL_H], | |||
[ | [ | |||
AC_REQUIRE([AC_HEADER_STDBOOL]) | AC_REQUIRE([AC_CHECK_HEADER_STDBOOL]) | |||
# Define two additional variables used in the Makefile substitution. | # Define two additional variables used in the Makefile substitution. | |||
if test "$ac_cv_header_stdbool_h" = yes; then | if test "$ac_cv_header_stdbool_h" = yes; then | |||
STDBOOL_H='' | STDBOOL_H='' | |||
else | else | |||
STDBOOL_H='stdbool.h' | STDBOOL_H='stdbool.h' | |||
fi | fi | |||
AC_SUBST([STDBOOL_H]) | AC_SUBST([STDBOOL_H]) | |||
AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"]) | ||||
if test "$ac_cv_type__Bool" = yes; then | if test "$ac_cv_type__Bool" = yes; then | |||
HAVE__BOOL=1 | HAVE__BOOL=1 | |||
else | else | |||
HAVE__BOOL=0 | HAVE__BOOL=0 | |||
fi | fi | |||
AC_SUBST([HAVE__BOOL]) | AC_SUBST([HAVE__BOOL]) | |||
]) | ]) | |||
# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future. | # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future. | |||
AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H]) | AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H]) | |||
# This macro is only needed in autoconf <= 2.59. Newer versions of autocon | # This version of the macro is needed in autoconf <= 2.68. | |||
f | ||||
# have this macro built-in. | ||||
AC_DEFUN([AC_HEADER_STDBOOL], | AC_DEFUN([AC_CHECK_HEADER_STDBOOL], | |||
[AC_CACHE_CHECK([for stdbool.h that conforms to C99], | [AC_CACHE_CHECK([for stdbool.h that conforms to C99], | |||
[ac_cv_header_stdbool_h], | [ac_cv_header_stdbool_h], | |||
[AC_TRY_COMPILE( | [AC_COMPILE_IFELSE( | |||
[ | [AC_LANG_PROGRAM( | |||
#include <stdbool.h> | [[ | |||
#ifndef bool | #include <stdbool.h> | |||
"error: bool is not defined" | #ifndef bool | |||
#endif | "error: bool is not defined" | |||
#ifndef false | #endif | |||
"error: false is not defined" | #ifndef false | |||
#endif | "error: false is not defined" | |||
#if false | #endif | |||
"error: false is not 0" | #if false | |||
#endif | "error: false is not 0" | |||
#ifndef true | #endif | |||
"error: true is not defined" | #ifndef true | |||
#endif | "error: true is not defined" | |||
#if true != 1 | #endif | |||
"error: true is not 1" | #if true != 1 | |||
#endif | "error: true is not 1" | |||
#ifndef __bool_true_false_are_defined | #endif | |||
"error: __bool_true_false_are_defined is not defined" | #ifndef __bool_true_false_are_defined | |||
#endif | "error: __bool_true_false_are_defined is not defined" | |||
#endif | ||||
struct s { _Bool s: 1; _Bool t; } s; | ||||
struct s { _Bool s: 1; _Bool t; } s; | ||||
char a[true == 1 ? 1 : -1]; | ||||
char b[false == 0 ? 1 : -1]; | char a[true == 1 ? 1 : -1]; | |||
char c[__bool_true_false_are_defined == 1 ? 1 : -1]; | char b[false == 0 ? 1 : -1]; | |||
char d[(bool) 0.5 == true ? 1 : -1]; | char c[__bool_true_false_are_defined == 1 ? 1 : -1]; | |||
bool e = &s; | char d[(bool) 0.5 == true ? 1 : -1]; | |||
char f[(_Bool) 0.0 == false ? 1 : -1]; | /* See body of main program for 'e'. */ | |||
char g[true]; | char f[(_Bool) 0.0 == false ? 1 : -1]; | |||
char h[sizeof (_Bool)]; | char g[true]; | |||
char i[sizeof s.t]; | char h[sizeof (_Bool)]; | |||
enum { j = false, k = true, l = false * true, m = true * 256 }; | char i[sizeof s.t]; | |||
_Bool n[m]; | enum { j = false, k = true, l = false * true, m = true * 256 } | |||
char o[sizeof n == m * sizeof n[0] ? 1 : -1]; | ; | |||
char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; | /* The following fails for | |||
#if defined __xlc__ || defined __GNUC__ | HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */ | |||
/* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 | _Bool n[m]; | |||
reported by James Lemley on 2005-10-05; see | char o[sizeof n == m * sizeof n[0] ? 1 : -1]; | |||
http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00 | char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; | |||
086.html | /* Catch a bug in an HP-UX C compiler. See | |||
This test is not quite right, since xlc is allowed to | http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html | |||
reject this program, as the initializer for xlcbug is | http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg | |||
not one of the forms that C requires support for. | 00161.html | |||
However, doing the test right would require a run-time | */ | |||
test, and that would make cross-compilation harder. | _Bool q = true; | |||
Let us hope that IBM fixes the xlc bug, and also adds | _Bool *pq = &q; | |||
support for this kind of constant expression. In the | ]], | |||
meantime, this test will reject xlc, which is OK, since | [[ | |||
our stdbool.h substitute should suffice. We also test | bool e = &s; | |||
this with GCC, where it should work, to detect more | *pq |= q; | |||
quickly whether someone messes up the test in the | *pq |= ! q; | |||
future. */ | /* Refer to every declared value, to avoid compiler optimizati | |||
char digs[] = "0123456789"; | ons. */ | |||
int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : - | return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k | |||
1); | + !!l | |||
#endif | + !m + !n + !o + !p + !q + !pq); | |||
/* Catch a bug in an HP-UX C compiler. See | ]])], | |||
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html | ||||
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg001 | ||||
61.html | ||||
*/ | ||||
_Bool q = true; | ||||
_Bool *pq = &q; | ||||
], | ||||
[ | ||||
*pq |= q; | ||||
*pq |= ! q; | ||||
/* Refer to every declared value, to avoid compiler optimizations | ||||
. */ | ||||
return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + ! | ||||
!l | ||||
+ !m + !n + !o + !p + !q + !pq); | ||||
], | ||||
[ac_cv_header_stdbool_h=yes], | [ac_cv_header_stdbool_h=yes], | |||
[ac_cv_header_stdbool_h=no])]) | [ac_cv_header_stdbool_h=no])]) | |||
AC_CHECK_TYPES([_Bool]) | AC_CHECK_TYPES([_Bool]) | |||
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]) | ||||
End of changes. 8 change blocks. | ||||
81 lines changed or deleted | 66 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |