|
version 1.1.1.2, 2012/05/29 09:29:43
|
version 1.1.1.3, 2021/03/17 13:38:46
|
|
Line 1
|
Line 1
|
| /* Copyright (C) 2001-2003, 2006-2011 Free Software Foundation, Inc. | /* Copyright (C) 2001-2003, 2006-2019 Free Software Foundation, Inc. |
| Written by Bruno Haible <haible@clisp.cons.org>, 2001. |
Written by Bruno Haible <haible@clisp.cons.org>, 2001. |
| |
|
| This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
|
Line 12
|
Line 12
|
| GNU General Public License for more details. |
GNU General Public License for more details. |
| |
|
| You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
| along with this program; if not, write to the Free Software Foundation, | along with this program; if not, see <https://www.gnu.org/licenses/>. */ |
| Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | |
| |
|
| #ifndef _GL_STDBOOL_H |
#ifndef _GL_STDBOOL_H |
| #define _GL_STDBOOL_H |
#define _GL_STDBOOL_H |
|
Line 67
|
Line 66
|
| # undef true |
# undef true |
| #endif |
#endif |
| |
|
| /* For the sake of symbolic names in gdb, we define true and false as | #ifdef __cplusplus |
| enum constants, not only as macros. | # define _Bool bool |
| It is tempting to write | # define bool bool |
| typedef enum { false = 0, true = 1 } _Bool; | #else |
| so that gdb prints values of type 'bool' symbolically. But if we do | # if defined __BEOS__ && !defined __HAIKU__ |
| this, values of type '_Bool' may promote to 'int' or 'unsigned int' | |
| (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int' | |
| (see ISO C 99 6.3.1.1.(2)). So we add a negative value to the | |
| enum; this ensures that '_Bool' promotes to 'int'. */ | |
| #if defined __cplusplus || (defined __BEOS__ && !defined __HAIKU__) | |
| /* A compiler known to have 'bool'. */ |
/* A compiler known to have 'bool'. */ |
| /* If the compiler already has both 'bool' and '_Bool', we can assume they |
/* If the compiler already has both 'bool' and '_Bool', we can assume they |
| are the same types. */ |
are the same types. */ |
| # if !@HAVE__BOOL@ | # if !@HAVE__BOOL@ |
| typedef bool _Bool; |
typedef bool _Bool; |
| # endif | # endif |
| #else | # else |
| # if !defined __GNUC__ | /* If @HAVE__BOOL@: |
| /* If @HAVE__BOOL@: |
/* If @HAVE__BOOL@: |
| Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when |
Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when |
| the built-in _Bool type is used. See |
the built-in _Bool type is used. See |
| http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html | https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html |
| http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html | https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html |
| http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html | https://lists.gnu.org/r/bug-coreutils/2005-10/msg00086.html |
| Similar bugs are likely with other compilers as well; this file |
Similar bugs are likely with other compilers as well; this file |
| wouldn't be used if <stdbool.h> was working. |
wouldn't be used if <stdbool.h> was working. |
| So we override the _Bool type. |
So we override the _Bool type. |
|
Line 104 typedef bool _Bool;
|
Line 98 typedef bool _Bool;
|
| "Invalid enumerator. (badenum)" with HP-UX cc on Tru64. |
"Invalid enumerator. (badenum)" with HP-UX cc on Tru64. |
| The only benefit of the enum, debuggability, is not important |
The only benefit of the enum, debuggability, is not important |
| with these compilers. So use 'signed char' and no enum. */ |
with these compilers. So use 'signed char' and no enum. */ |
| # define _Bool signed char | # define _Bool signed char |
| # else | # else |
| /* With this compiler, trust the _Bool type if the compiler has it. */ |
/* With this compiler, trust the _Bool type if the compiler has it. */ |
| # if !@HAVE__BOOL@ | # if !@HAVE__BOOL@ |
| | /* For the sake of symbolic names in gdb, define true and false as |
| | enum constants, not only as macros. |
| | It is tempting to write |
| | typedef enum { false = 0, true = 1 } _Bool; |
| | so that gdb prints values of type 'bool' symbolically. But then |
| | values of type '_Bool' might promote to 'int' or 'unsigned int' |
| | (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int' |
| | (see ISO C 99 6.3.1.1.(2)). So add a negative value to the |
| | enum; this ensures that '_Bool' promotes to 'int'. */ |
| typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool; |
typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool; |
| |
# endif |
| # endif |
# endif |
| # endif |
# endif |
| |
# define bool _Bool |
| #endif |
#endif |
| #define bool _Bool |
|
| |
|
| /* The other macros must be usable in preprocessor directives. */ |
/* The other macros must be usable in preprocessor directives. */ |
| #define false 0 | #ifdef __cplusplus |
| #define true 1 | # define false false |
| | # define true true |
| | #else |
| | # define false 0 |
| | # define true 1 |
| | #endif |
| | |
| #define __bool_true_false_are_defined 1 |
#define __bool_true_false_are_defined 1 |
| |
|
| #endif /* _GL_STDBOOL_H */ |
#endif /* _GL_STDBOOL_H */ |