1*7330f729Sjoerg /*===---- limits.h - Standard header for integer sizes --------------------===*\ 2*7330f729Sjoerg * 3*7330f729Sjoerg * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*7330f729Sjoerg * See https://llvm.org/LICENSE.txt for license information. 5*7330f729Sjoerg * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*7330f729Sjoerg * 7*7330f729Sjoerg \*===----------------------------------------------------------------------===*/ 8*7330f729Sjoerg 9*7330f729Sjoerg #ifndef __CLANG_LIMITS_H 10*7330f729Sjoerg #define __CLANG_LIMITS_H 11*7330f729Sjoerg 12*7330f729Sjoerg /* The system's limits.h may, in turn, try to #include_next GCC's limits.h. 13*7330f729Sjoerg Avert this #include_next madness. */ 14*7330f729Sjoerg #if defined __GNUC__ && !defined _GCC_LIMITS_H_ 15*7330f729Sjoerg #define _GCC_LIMITS_H_ 16*7330f729Sjoerg #endif 17*7330f729Sjoerg 18*7330f729Sjoerg /* System headers include a number of constants from POSIX in <limits.h>. 19*7330f729Sjoerg Include it if we're hosted. */ 20*7330f729Sjoerg #if __STDC_HOSTED__ && __has_include_next(<limits.h>) 21*7330f729Sjoerg #include_next <limits.h> 22*7330f729Sjoerg #endif 23*7330f729Sjoerg 24*7330f729Sjoerg /* Many system headers try to "help us out" by defining these. No really, we 25*7330f729Sjoerg know how big each datatype is. */ 26*7330f729Sjoerg #undef SCHAR_MIN 27*7330f729Sjoerg #undef SCHAR_MAX 28*7330f729Sjoerg #undef UCHAR_MAX 29*7330f729Sjoerg #undef SHRT_MIN 30*7330f729Sjoerg #undef SHRT_MAX 31*7330f729Sjoerg #undef USHRT_MAX 32*7330f729Sjoerg #undef INT_MIN 33*7330f729Sjoerg #undef INT_MAX 34*7330f729Sjoerg #undef UINT_MAX 35*7330f729Sjoerg #undef LONG_MIN 36*7330f729Sjoerg #undef LONG_MAX 37*7330f729Sjoerg #undef ULONG_MAX 38*7330f729Sjoerg 39*7330f729Sjoerg #undef CHAR_BIT 40*7330f729Sjoerg #undef CHAR_MIN 41*7330f729Sjoerg #undef CHAR_MAX 42*7330f729Sjoerg 43*7330f729Sjoerg /* C90/99 5.2.4.2.1 */ 44*7330f729Sjoerg #define SCHAR_MAX __SCHAR_MAX__ 45*7330f729Sjoerg #define SHRT_MAX __SHRT_MAX__ 46*7330f729Sjoerg #define INT_MAX __INT_MAX__ 47*7330f729Sjoerg #define LONG_MAX __LONG_MAX__ 48*7330f729Sjoerg 49*7330f729Sjoerg #define SCHAR_MIN (-__SCHAR_MAX__-1) 50*7330f729Sjoerg #define SHRT_MIN (-__SHRT_MAX__ -1) 51*7330f729Sjoerg #define INT_MIN (-__INT_MAX__ -1) 52*7330f729Sjoerg #define LONG_MIN (-__LONG_MAX__ -1L) 53*7330f729Sjoerg 54*7330f729Sjoerg #define UCHAR_MAX (__SCHAR_MAX__*2 +1) 55*7330f729Sjoerg #define USHRT_MAX (__SHRT_MAX__ *2 +1) 56*7330f729Sjoerg #define UINT_MAX (__INT_MAX__ *2U +1U) 57*7330f729Sjoerg #define ULONG_MAX (__LONG_MAX__ *2UL+1UL) 58*7330f729Sjoerg 59*7330f729Sjoerg #ifndef MB_LEN_MAX 60*7330f729Sjoerg #define MB_LEN_MAX 1 61*7330f729Sjoerg #endif 62*7330f729Sjoerg 63*7330f729Sjoerg #define CHAR_BIT __CHAR_BIT__ 64*7330f729Sjoerg 65*7330f729Sjoerg #ifdef __CHAR_UNSIGNED__ /* -funsigned-char */ 66*7330f729Sjoerg #define CHAR_MIN 0 67*7330f729Sjoerg #define CHAR_MAX UCHAR_MAX 68*7330f729Sjoerg #else 69*7330f729Sjoerg #define CHAR_MIN SCHAR_MIN 70*7330f729Sjoerg #define CHAR_MAX __SCHAR_MAX__ 71*7330f729Sjoerg #endif 72*7330f729Sjoerg 73*7330f729Sjoerg /* C99 5.2.4.2.1: Added long long. 74*7330f729Sjoerg C++11 18.3.3.2: same contents as the Standard C Library header <limits.h>. 75*7330f729Sjoerg */ 76*7330f729Sjoerg #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L 77*7330f729Sjoerg 78*7330f729Sjoerg #undef LLONG_MIN 79*7330f729Sjoerg #undef LLONG_MAX 80*7330f729Sjoerg #undef ULLONG_MAX 81*7330f729Sjoerg 82*7330f729Sjoerg #define LLONG_MAX __LONG_LONG_MAX__ 83*7330f729Sjoerg #define LLONG_MIN (-__LONG_LONG_MAX__-1LL) 84*7330f729Sjoerg #define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL) 85*7330f729Sjoerg #endif 86*7330f729Sjoerg 87*7330f729Sjoerg /* LONG_LONG_MIN/LONG_LONG_MAX/ULONG_LONG_MAX are a GNU extension. It's too bad 88*7330f729Sjoerg that we don't have something like #pragma poison that could be used to 89*7330f729Sjoerg deprecate a macro - the code should just use LLONG_MAX and friends. 90*7330f729Sjoerg */ 91*7330f729Sjoerg #if defined(__GNU_LIBRARY__) ? defined(__USE_GNU) : !defined(__STRICT_ANSI__) 92*7330f729Sjoerg 93*7330f729Sjoerg #undef LONG_LONG_MIN 94*7330f729Sjoerg #undef LONG_LONG_MAX 95*7330f729Sjoerg #undef ULONG_LONG_MAX 96*7330f729Sjoerg 97*7330f729Sjoerg #define LONG_LONG_MAX __LONG_LONG_MAX__ 98*7330f729Sjoerg #define LONG_LONG_MIN (-__LONG_LONG_MAX__-1LL) 99*7330f729Sjoerg #define ULONG_LONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL) 100*7330f729Sjoerg #endif 101*7330f729Sjoerg 102*7330f729Sjoerg #endif /* __CLANG_LIMITS_H */ 103