limits.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*===---- limits.h - Standard header for integer sizes --------------------===*\
  2. *
  3. * Copyright (c) 2009 Chris Lattner
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. *
  23. \*===----------------------------------------------------------------------===*/
  24. #ifndef __CLANG_LIMITS_H
  25. #define __CLANG_LIMITS_H
  26. /* The system's limits.h may, in turn, try to #include_next GCC's limits.h.
  27. Avert this #include_next madness. */
  28. #if defined __GNUC__ && !defined _GCC_LIMITS_H_
  29. #define _GCC_LIMITS_H_
  30. #endif
  31. /* System headers include a number of constants from POSIX in <limits.h>.
  32. Include it if we're hosted. */
  33. #if __STDC_HOSTED__ && __has_include_next(<limits.h>)
  34. #include_next <limits.h>
  35. #endif
  36. /* Many system headers try to "help us out" by defining these. No really, we
  37. know how big each datatype is. */
  38. #undef SCHAR_MIN
  39. #undef SCHAR_MAX
  40. #undef UCHAR_MAX
  41. #undef SHRT_MIN
  42. #undef SHRT_MAX
  43. #undef USHRT_MAX
  44. #undef INT_MIN
  45. #undef INT_MAX
  46. #undef UINT_MAX
  47. #undef LONG_MIN
  48. #undef LONG_MAX
  49. #undef ULONG_MAX
  50. #undef CHAR_BIT
  51. #undef CHAR_MIN
  52. #undef CHAR_MAX
  53. /* C90/99 5.2.4.2.1 */
  54. #define SCHAR_MAX __SCHAR_MAX__
  55. #define SHRT_MAX __SHRT_MAX__
  56. #define INT_MAX __INT_MAX__
  57. #define LONG_MAX __LONG_MAX__
  58. #define SCHAR_MIN (-__SCHAR_MAX__-1)
  59. #define SHRT_MIN (-__SHRT_MAX__ -1)
  60. #define INT_MIN (-__INT_MAX__ -1)
  61. #define LONG_MIN (-__LONG_MAX__ -1L)
  62. #define UCHAR_MAX (__SCHAR_MAX__*2 +1)
  63. #define USHRT_MAX (__SHRT_MAX__ *2 +1)
  64. #define UINT_MAX (__INT_MAX__ *2U +1U)
  65. #define ULONG_MAX (__LONG_MAX__ *2UL+1UL)
  66. #ifndef MB_LEN_MAX
  67. #define MB_LEN_MAX 1
  68. #endif
  69. #define CHAR_BIT __CHAR_BIT__
  70. #ifdef __CHAR_UNSIGNED__ /* -funsigned-char */
  71. #define CHAR_MIN 0
  72. #define CHAR_MAX UCHAR_MAX
  73. #else
  74. #define CHAR_MIN SCHAR_MIN
  75. #define CHAR_MAX __SCHAR_MAX__
  76. #endif
  77. /* C99 5.2.4.2.1: Added long long.
  78. C++11 18.3.3.2: same contents as the Standard C Library header <limits.h>.
  79. */
  80. #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
  81. #undef LLONG_MIN
  82. #undef LLONG_MAX
  83. #undef ULLONG_MAX
  84. #define LLONG_MAX __LONG_LONG_MAX__
  85. #define LLONG_MIN (-__LONG_LONG_MAX__-1LL)
  86. #define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
  87. #endif
  88. /* LONG_LONG_MIN/LONG_LONG_MAX/ULONG_LONG_MAX are a GNU extension. It's too bad
  89. that we don't have something like #pragma poison that could be used to
  90. deprecate a macro - the code should just use LLONG_MAX and friends.
  91. */
  92. #if defined(__GNU_LIBRARY__) ? defined(__USE_GNU) : !defined(__STRICT_ANSI__)
  93. #undef LONG_LONG_MIN
  94. #undef LONG_LONG_MAX
  95. #undef ULONG_LONG_MAX
  96. #define LONG_LONG_MAX __LONG_LONG_MAX__
  97. #define LONG_LONG_MIN (-__LONG_LONG_MAX__-1LL)
  98. #define ULONG_LONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
  99. #endif
  100. #endif /* __CLANG_LIMITS_H */