Back to index

nagios-plugins  1.4.16
stdbool.in.h
Go to the documentation of this file.
00001 /* Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc.
00002    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 3, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software Foundation,
00016    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
00017 
00018 #ifndef _GL_STDBOOL_H
00019 #define _GL_STDBOOL_H
00020 
00021 /* ISO C 99 <stdbool.h> for platforms that lack it.  */
00022 
00023 /* Usage suggestions:
00024 
00025    Programs that use <stdbool.h> should be aware of some limitations
00026    and standards compliance issues.
00027 
00028    Standards compliance:
00029 
00030        - <stdbool.h> must be #included before 'bool', 'false', 'true'
00031          can be used.
00032 
00033        - You cannot assume that sizeof (bool) == 1.
00034 
00035        - Programs should not undefine the macros bool, true, and false,
00036          as C99 lists that as an "obsolescent feature".
00037 
00038    Limitations of this substitute, when used in a C89 environment:
00039 
00040        - <stdbool.h> must be #included before the '_Bool' type can be used.
00041 
00042        - You cannot assume that _Bool is a typedef; it might be a macro.
00043 
00044        - Bit-fields of type 'bool' are not supported.  Portable code
00045          should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
00046 
00047        - In C99, casts and automatic conversions to '_Bool' or 'bool' are
00048          performed in such a way that every nonzero value gets converted
00049          to 'true', and zero gets converted to 'false'.  This doesn't work
00050          with this substitute.  With this substitute, only the values 0 and 1
00051          give the expected result when converted to _Bool' or 'bool'.
00052 
00053        - C99 allows the use of (_Bool)0.0 in constant expressions, but
00054          this substitute cannot always provide this property.
00055 
00056    Also, it is suggested that programs use 'bool' rather than '_Bool';
00057    this isn't required, but 'bool' is more common.  */
00058 
00059 
00060 /* 7.16. Boolean type and values */
00061 
00062 /* BeOS <sys/socket.h> already #defines false 0, true 1.  We use the same
00063    definitions below, but temporarily we have to #undef them.  */
00064 #if defined __BEOS__ && !defined __HAIKU__
00065 # include <OS.h> /* defines bool but not _Bool */
00066 # undef false
00067 # undef true
00068 #endif
00069 
00070 /* For the sake of symbolic names in gdb, we define true and false as
00071    enum constants, not only as macros.
00072    It is tempting to write
00073       typedef enum { false = 0, true = 1 } _Bool;
00074    so that gdb prints values of type 'bool' symbolically. But if we do
00075    this, values of type '_Bool' may promote to 'int' or 'unsigned int'
00076    (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
00077    (see ISO C 99 6.3.1.1.(2)).  So we add a negative value to the
00078    enum; this ensures that '_Bool' promotes to 'int'.  */
00079 #if defined __cplusplus || (defined __BEOS__ && !defined __HAIKU__)
00080   /* A compiler known to have 'bool'.  */
00081   /* If the compiler already has both 'bool' and '_Bool', we can assume they
00082      are the same types.  */
00083 # if !@HAVE__BOOL@
00084 typedef bool _Bool;
00085 # endif
00086 #else
00087 # if !defined __GNUC__
00088    /* If @HAVE__BOOL@:
00089         Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
00090         the built-in _Bool type is used.  See
00091           http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
00092           http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
00093           http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
00094         Similar bugs are likely with other compilers as well; this file
00095         wouldn't be used if <stdbool.h> was working.
00096         So we override the _Bool type.
00097       If !@HAVE__BOOL@:
00098         Need to define _Bool ourselves. As 'signed char' or as an enum type?
00099         Use of a typedef, with SunPRO C, leads to a stupid
00100           "warning: _Bool is a keyword in ISO C99".
00101         Use of an enum type, with IRIX cc, leads to a stupid
00102           "warning(1185): enumerated type mixed with another type".
00103         Even the existence of an enum type, without a typedef,
00104           "Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
00105         The only benefit of the enum, debuggability, is not important
00106         with these compilers.  So use 'signed char' and no enum.  */
00107 #  define _Bool signed char
00108 # else
00109    /* With this compiler, trust the _Bool type if the compiler has it.  */
00110 #  if !@HAVE__BOOL@
00111 typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
00112 #  endif
00113 # endif
00114 #endif
00115 #define bool _Bool
00116 
00117 /* The other macros must be usable in preprocessor directives.  */
00118 #define false 0
00119 #define true 1
00120 #define __bool_true_false_are_defined 1
00121 
00122 #endif /* _GL_STDBOOL_H */