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