d89580181384787d3076aebadfa816a8db61207b
[debian/tar] / gnu / stdbool.in.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc.
4    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3, or (at your option)
9    any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _GL_STDBOOL_H
20 #define _GL_STDBOOL_H
21
22 /* ISO C 99 <stdbool.h> for platforms that lack it.  */
23
24 /* Usage suggestions:
25
26    Programs that use <stdbool.h> should be aware of some limitations
27    and standards compliance issues.
28
29    Standards compliance:
30
31        - <stdbool.h> must be #included before 'bool', 'false', 'true'
32          can be used.
33
34        - You cannot assume that sizeof (bool) == 1.
35
36        - Programs should not undefine the macros bool, true, and false,
37          as C99 lists that as an "obsolescent feature".
38
39    Limitations of this substitute, when used in a C89 environment:
40
41        - <stdbool.h> must be #included before the '_Bool' type can be used.
42
43        - You cannot assume that _Bool is a typedef; it might be a macro.
44
45        - Bit-fields of type 'bool' are not supported.  Portable code
46          should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
47
48        - In C99, casts and automatic conversions to '_Bool' or 'bool' are
49          performed in such a way that every nonzero value gets converted
50          to 'true', and zero gets converted to 'false'.  This doesn't work
51          with this substitute.  With this substitute, only the values 0 and 1
52          give the expected result when converted to _Bool' or 'bool'.
53
54        - C99 allows the use of (_Bool)0.0 in constant expressions, but
55          this substitute cannot always provide this property.
56
57    Also, it is suggested that programs use 'bool' rather than '_Bool';
58    this isn't required, but 'bool' is more common.  */
59
60
61 /* 7.16. Boolean type and values */
62
63 /* BeOS <sys/socket.h> already #defines false 0, true 1.  We use the same
64    definitions below, but temporarily we have to #undef them.  */
65 #if defined __BEOS__ && !defined __HAIKU__
66 # include <OS.h> /* defines bool but not _Bool */
67 # undef false
68 # undef true
69 #endif
70
71 #ifdef __cplusplus
72 # define _Bool bool
73 # define bool bool
74 #else
75 # if defined __BEOS__ && !defined __HAIKU__
76   /* A compiler known to have 'bool'.  */
77   /* If the compiler already has both 'bool' and '_Bool', we can assume they
78      are the same types.  */
79 #  if !@HAVE__BOOL@
80 typedef bool _Bool;
81 #  endif
82 # else
83 #  if !defined __GNUC__
84    /* If @HAVE__BOOL@:
85         Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
86         the built-in _Bool type is used.  See
87           http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
88           http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
89           http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
90         Similar bugs are likely with other compilers as well; this file
91         wouldn't be used if <stdbool.h> was working.
92         So we override the _Bool type.
93       If !@HAVE__BOOL@:
94         Need to define _Bool ourselves. As 'signed char' or as an enum type?
95         Use of a typedef, with SunPRO C, leads to a stupid
96           "warning: _Bool is a keyword in ISO C99".
97         Use of an enum type, with IRIX cc, leads to a stupid
98           "warning(1185): enumerated type mixed with another type".
99         Even the existence of an enum type, without a typedef,
100           "Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
101         The only benefit of the enum, debuggability, is not important
102         with these compilers.  So use 'signed char' and no enum.  */
103 #   define _Bool signed char
104 #  else
105    /* With this compiler, trust the _Bool type if the compiler has it.  */
106 #   if !@HAVE__BOOL@
107    /* For the sake of symbolic names in gdb, define true and false as
108       enum constants, not only as macros.
109       It is tempting to write
110          typedef enum { false = 0, true = 1 } _Bool;
111       so that gdb prints values of type 'bool' symbolically.  But then
112       values of type '_Bool' might promote to 'int' or 'unsigned int'
113       (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
114       (see ISO C 99 6.3.1.1.(2)).  So add a negative value to the
115       enum; this ensures that '_Bool' promotes to 'int'.  */
116 typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
117 #   endif
118 #  endif
119 # endif
120 # define bool _Bool
121 #endif
122
123 /* The other macros must be usable in preprocessor directives.  */
124 #ifdef __cplusplus
125 # define false false
126 # define true true
127 #else
128 # define false 0
129 # define true 1
130 #endif
131
132 #define __bool_true_false_are_defined 1
133
134 #endif /* _GL_STDBOOL_H */