Blame gl/stdbool.in.h

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