Blame lib/stdbool.in.h

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