Blame gl/stdbool.in.h

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