stdbool.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
  2. /* Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc.
  3. Written by Bruno Haible <haible@clisp.cons.org>, 2001.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef _GL_STDBOOL_H
  15. #define _GL_STDBOOL_H
  16. /* ISO C 99 <stdbool.h> for platforms that lack it. */
  17. /* Usage suggestions:
  18. Programs that use <stdbool.h> should be aware of some limitations
  19. and standards compliance issues.
  20. Standards compliance:
  21. - <stdbool.h> must be #included before 'bool', 'false', 'true'
  22. can be used.
  23. - You cannot assume that sizeof (bool) == 1.
  24. - Programs should not undefine the macros bool, true, and false,
  25. as C99 lists that as an "obsolescent feature".
  26. Limitations of this substitute, when used in a C89 environment:
  27. - <stdbool.h> must be #included before the '_Bool' type can be used.
  28. - You cannot assume that _Bool is a typedef; it might be a macro.
  29. - Bit-fields of type 'bool' are not supported. Portable code
  30. should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
  31. - In C99, casts and automatic conversions to '_Bool' or 'bool' are
  32. performed in such a way that every nonzero value gets converted
  33. to 'true', and zero gets converted to 'false'. This doesn't work
  34. with this substitute. With this substitute, only the values 0 and 1
  35. give the expected result when converted to _Bool' or 'bool'.
  36. - C99 allows the use of (_Bool)0.0 in constant expressions, but
  37. this substitute cannot always provide this property.
  38. Also, it is suggested that programs use 'bool' rather than '_Bool';
  39. this isn't required, but 'bool' is more common. */
  40. /* 7.16. Boolean type and values */
  41. /* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
  42. definitions below, but temporarily we have to #undef them. */
  43. #if defined __BEOS__ && !defined __HAIKU__
  44. # error #include <OS.h> /* defines bool but not _Bool */
  45. # undef false
  46. # undef true
  47. #endif
  48. #ifdef __cplusplus
  49. # define _Bool bool
  50. # define bool bool
  51. #else
  52. # if defined __BEOS__ && !defined __HAIKU__
  53. /* A compiler known to have 'bool'. */
  54. /* If the compiler already has both 'bool' and '_Bool', we can assume they
  55. are the same types. */
  56. # if !0
  57. typedef bool _Bool;
  58. # endif
  59. # else
  60. # if !defined __GNUC__
  61. /* If 0:
  62. Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
  63. the built-in _Bool type is used. See
  64. http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
  65. http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
  66. http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
  67. Similar bugs are likely with other compilers as well; this file
  68. wouldn't be used if <stdbool.h> was working.
  69. So we override the _Bool type.
  70. If !0:
  71. Need to define _Bool ourselves. As 'signed char' or as an enum type?
  72. Use of a typedef, with SunPRO C, leads to a stupid
  73. "warning: _Bool is a keyword in ISO C99".
  74. Use of an enum type, with IRIX cc, leads to a stupid
  75. "warning(1185): enumerated type mixed with another type".
  76. Even the existence of an enum type, without a typedef,
  77. "Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
  78. The only benefit of the enum, debuggability, is not important
  79. with these compilers. So use 'signed char' and no enum. */
  80. # define _Bool signed char
  81. # else
  82. /* With this compiler, trust the _Bool type if the compiler has it. */
  83. # if !0
  84. /* For the sake of symbolic names in gdb, define true and false as
  85. enum constants, not only as macros.
  86. It is tempting to write
  87. typedef enum { false = 0, true = 1 } _Bool;
  88. so that gdb prints values of type 'bool' symbolically. But then
  89. values of type '_Bool' might promote to 'int' or 'unsigned int'
  90. (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
  91. (see ISO C 99 6.3.1.1.(2)). So add a negative value to the
  92. enum; this ensures that '_Bool' promotes to 'int'. */
  93. typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
  94. # endif
  95. # endif
  96. # endif
  97. # define bool _Bool
  98. #endif
  99. /* The other macros must be usable in preprocessor directives. */
  100. #ifdef __cplusplus
  101. # define false false
  102. # define true true
  103. #else
  104. # define false 0
  105. # define true 1
  106. #endif
  107. #define __bool_true_false_are_defined 1
  108. #endif /* _GL_STDBOOL_H */