Blame lib/unistring/stdbool.in.h

Packit Service 991b93
/* Copyright (C) 2001-2003, 2006-2020 Free Software Foundation, Inc.
Packit aea12f
   Written by Bruno Haible <haible@clisp.cons.org>, 2001.
Packit aea12f
Packit aea12f
   This program is free software: you can redistribute it and/or
Packit aea12f
   modify it under the terms of either:
Packit aea12f
Packit aea12f
     * the GNU Lesser General Public License as published by the Free
Packit aea12f
       Software Foundation; either version 3 of the License, or (at your
Packit aea12f
       option) any later version.
Packit aea12f
Packit aea12f
   or
Packit aea12f
Packit aea12f
     * the GNU General Public License as published by the Free
Packit aea12f
       Software Foundation; either version 2 of the License, or (at your
Packit aea12f
       option) any later version.
Packit aea12f
Packit aea12f
   or both in parallel, as here.
Packit aea12f
   This program is distributed in the hope that it will be useful,
Packit aea12f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit aea12f
   GNU General Public License for more details.
Packit aea12f
Packit aea12f
   You should have received a copy of the GNU General Public License
Packit aea12f
   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
Packit aea12f
Packit aea12f
#ifndef _GL_STDBOOL_H
Packit aea12f
#define _GL_STDBOOL_H
Packit aea12f
Packit aea12f
/* ISO C 99 <stdbool.h> for platforms that lack it.  */
Packit aea12f
Packit aea12f
/* Usage suggestions:
Packit aea12f
Packit aea12f
   Programs that use <stdbool.h> should be aware of some limitations
Packit aea12f
   and standards compliance issues.
Packit aea12f
Packit aea12f
   Standards compliance:
Packit aea12f
Packit aea12f
       - <stdbool.h> must be #included before 'bool', 'false', 'true'
Packit aea12f
         can be used.
Packit aea12f
Packit aea12f
       - You cannot assume that sizeof (bool) == 1.
Packit aea12f
Packit aea12f
       - Programs should not undefine the macros bool, true, and false,
Packit aea12f
         as C99 lists that as an "obsolescent feature".
Packit aea12f
Packit aea12f
   Limitations of this substitute, when used in a C89 environment:
Packit aea12f
Packit aea12f
       - <stdbool.h> must be #included before the '_Bool' type can be used.
Packit aea12f
Packit aea12f
       - You cannot assume that _Bool is a typedef; it might be a macro.
Packit aea12f
Packit aea12f
       - Bit-fields of type 'bool' are not supported.  Portable code
Packit aea12f
         should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
Packit aea12f
Packit aea12f
       - In C99, casts and automatic conversions to '_Bool' or 'bool' are
Packit aea12f
         performed in such a way that every nonzero value gets converted
Packit aea12f
         to 'true', and zero gets converted to 'false'.  This doesn't work
Packit aea12f
         with this substitute.  With this substitute, only the values 0 and 1
Packit aea12f
         give the expected result when converted to _Bool' or 'bool'.
Packit aea12f
Packit aea12f
       - C99 allows the use of (_Bool)0.0 in constant expressions, but
Packit aea12f
         this substitute cannot always provide this property.
Packit aea12f
Packit aea12f
   Also, it is suggested that programs use 'bool' rather than '_Bool';
Packit aea12f
   this isn't required, but 'bool' is more common.  */
Packit aea12f
Packit aea12f
Packit aea12f
/* 7.16. Boolean type and values */
Packit aea12f
Packit aea12f
/* BeOS <sys/socket.h> already #defines false 0, true 1.  We use the same
Packit aea12f
   definitions below, but temporarily we have to #undef them.  */
Packit aea12f
#if defined __BEOS__ && !defined __HAIKU__
Packit aea12f
# include <OS.h> /* defines bool but not _Bool */
Packit aea12f
# undef false
Packit aea12f
# undef true
Packit aea12f
#endif
Packit aea12f
Packit aea12f
#ifdef __cplusplus
Packit aea12f
# define _Bool bool
Packit aea12f
# define bool bool
Packit aea12f
#else
Packit aea12f
# if defined __BEOS__ && !defined __HAIKU__
Packit aea12f
  /* A compiler known to have 'bool'.  */
Packit aea12f
  /* If the compiler already has both 'bool' and '_Bool', we can assume they
Packit aea12f
     are the same types.  */
Packit aea12f
#  if !@HAVE__BOOL@
Packit aea12f
typedef bool _Bool;
Packit aea12f
#  endif
Packit aea12f
# else
Packit aea12f
#  if !defined __GNUC__
Packit aea12f
   /* If @HAVE__BOOL@:
Packit aea12f
        Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
Packit aea12f
        the built-in _Bool type is used.  See
Packit aea12f
          https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
Packit aea12f
          https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
Packit aea12f
          https://lists.gnu.org/r/bug-coreutils/2005-10/msg00086.html
Packit aea12f
        Similar bugs are likely with other compilers as well; this file
Packit aea12f
        wouldn't be used if <stdbool.h> was working.
Packit aea12f
        So we override the _Bool type.
Packit aea12f
      If !@HAVE__BOOL@:
Packit aea12f
        Need to define _Bool ourselves. As 'signed char' or as an enum type?
Packit aea12f
        Use of a typedef, with SunPRO C, leads to a stupid
Packit aea12f
          "warning: _Bool is a keyword in ISO C99".
Packit aea12f
        Use of an enum type, with IRIX cc, leads to a stupid
Packit aea12f
          "warning(1185): enumerated type mixed with another type".
Packit aea12f
        Even the existence of an enum type, without a typedef,
Packit aea12f
          "Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
Packit aea12f
        The only benefit of the enum, debuggability, is not important
Packit aea12f
        with these compilers.  So use 'signed char' and no enum.  */
Packit aea12f
#   define _Bool signed char
Packit aea12f
#  else
Packit aea12f
   /* With this compiler, trust the _Bool type if the compiler has it.  */
Packit aea12f
#   if !@HAVE__BOOL@
Packit aea12f
   /* For the sake of symbolic names in gdb, define true and false as
Packit aea12f
      enum constants, not only as macros.
Packit aea12f
      It is tempting to write
Packit aea12f
         typedef enum { false = 0, true = 1 } _Bool;
Packit aea12f
      so that gdb prints values of type 'bool' symbolically.  But then
Packit aea12f
      values of type '_Bool' might promote to 'int' or 'unsigned int'
Packit aea12f
      (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
Packit aea12f
      (see ISO C 99 6.3.1.1.(2)).  So add a negative value to the
Packit aea12f
      enum; this ensures that '_Bool' promotes to 'int'.  */
Packit aea12f
typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
Packit aea12f
#   endif
Packit aea12f
#  endif
Packit aea12f
# endif
Packit aea12f
# define bool _Bool
Packit aea12f
#endif
Packit aea12f
Packit aea12f
/* The other macros must be usable in preprocessor directives.  */
Packit aea12f
#ifdef __cplusplus
Packit aea12f
# define false false
Packit aea12f
# define true true
Packit aea12f
#else
Packit aea12f
# define false 0
Packit aea12f
# define true 1
Packit aea12f
#endif
Packit aea12f
Packit aea12f
#define __bool_true_false_are_defined 1
Packit aea12f
Packit aea12f
#endif /* _GL_STDBOOL_H */