summaryrefslogtreecommitdiffstats
path: root/lib/stdbool_.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stdbool_.h')
-rw-r--r--lib/stdbool_.h54
1 files changed, 33 insertions, 21 deletions
diff --git a/lib/stdbool_.h b/lib/stdbool_.h
index e33715a6..7cd2da84 100644
--- a/lib/stdbool_.h
+++ b/lib/stdbool_.h
@@ -1,4 +1,4 @@
1/* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. 1/* Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
2 Written by Bruno Haible <haible@clisp.cons.org>, 2001. 2 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
@@ -13,7 +13,7 @@
13 13
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation, 15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17 17
18#ifndef _STDBOOL_H 18#ifndef _STDBOOL_H
19#define _STDBOOL_H 19#define _STDBOOL_H
@@ -54,35 +54,47 @@
54/* 7.16. Boolean type and values */ 54/* 7.16. Boolean type and values */
55 55
56/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same 56/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
57 definitions below, but temporarily we have to #undef them. */ 57 definitions below, which is OK. */
58#ifdef __BEOS__ 58#ifdef __BEOS__
59# include <OS.h> /* defines bool but not _Bool */ 59# include <OS.h> /* defines bool but not _Bool */
60# undef false
61# undef true
62#endif 60#endif
63 61
64/* For the sake of symbolic names in gdb, we define true and false as 62/* C++ and BeOS have a reliable bool (and _Bool, if it exists).
65 enum constants, not only as macros. 63 Otherwise, since this file is being compiled, the system
66 It is tempting to write 64 <stdbool.h> is not reliable so assume that the system _Bool is not
67 typedef enum { false = 0, true = 1 } _Bool; 65 reliable either. Under that assumption, it is tempting to write
68 so that gdb prints values of type 'bool' symbolically. But if we do 66
67 typedef enum { false, true } _Bool;
68
69 so that gdb prints values of type 'bool' symbolically. But if we do
69 this, values of type '_Bool' may promote to 'int' or 'unsigned int' 70 this, values of type '_Bool' may promote to 'int' or 'unsigned int'
70 (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int' 71 (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
71 (see ISO C 99 6.3.1.1.(2)). So we add a negative value to the 72 (see ISO C 99 6.3.1.1.(2)). We could instead try this:
72 enum; this ensures that '_Bool' promotes to 'int'. */ 73
73#if !(defined __cplusplus || defined __BEOS__) 74 typedef enum { _Bool_dummy = -1, false, true } _Bool;
75
76 as the negative value ensures that '_Bool' promotes to 'int'.
77 However, this runs into some other problems. First, Sun's C
78 compiler when (__SUNPRO_C < 0x550 || __STDC__ == 1) issues a stupid
79 "warning: _Bool is a keyword in ISO C99". Second, IBM's AIX cc
80 compiler 6.0.0.0 (and presumably other versions) mishandles
81 subscripts involving _Bool (effectively, _Bool promotes to unsigned
82 int in this case), and we need to redefine _Bool in that case.
83 Third, HP-UX 10.20's C compiler lacks <stdbool.h> but has _Bool and
84 mishandles comparisons of _Bool to int (it promotes _Bool to
85 unsigned int).
86
87 The simplest way to work around these problems is to ignore any
88 existing definition of _Bool and use our own. */
89
90#if defined __cplusplus || defined __BEOS__
74# if !@HAVE__BOOL@ 91# if !@HAVE__BOOL@
75# if defined __SUNPRO_C && (__SUNPRO_C < 0x550 || __STDC__ == 1) 92typedef bool _Bool;
76 /* Avoid stupid "warning: _Bool is a keyword in ISO C99". */
77# define _Bool signed char
78enum { false = 0, true = 1 };
79# else
80typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
81# endif
82# endif 93# endif
83#else 94#else
84typedef bool _Bool; 95# define _Bool signed char
85#endif 96#endif
97
86#define bool _Bool 98#define bool _Bool
87 99
88/* The other macros must be usable in preprocessor directives. */ 100/* The other macros must be usable in preprocessor directives. */