Blame gettext-runtime/gnulib-lib/stdbool.in.h

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