Chris Lattner | a9cece6 | 2009-02-06 18:45:59 +0000 | [diff] [blame] | 1 | /*===---- limits.h - Standard header for integer sizes --------------------===*\ |
Chris Lattner | c807423 | 2009-02-06 18:34:27 +0000 | [diff] [blame] | 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 | * |
Chris Lattner | 2a67f7b | 2009-02-06 22:59:47 +0000 | [diff] [blame] | 23 | \*===----------------------------------------------------------------------===*/ |
Chris Lattner | c807423 | 2009-02-06 18:34:27 +0000 | [diff] [blame] | 24 | |
Mike Stump | 3855b9a | 2009-02-12 23:06:31 +0000 | [diff] [blame] | 25 | #ifndef __CLANG_LIMITS_H |
| 26 | #define __CLANG_LIMITS_H |
| 27 | |
| 28 | /* The system's limits.h may, in turn, try to #include_next GCC's limits.h. |
| 29 | Avert this #include_next madness. */ |
| 30 | #if defined __GNUC__ && !defined _GCC_LIMITS_H_ |
| 31 | #define _GCC_LIMITS_H_ |
| 32 | #endif |
Chris Lattner | c807423 | 2009-02-06 18:34:27 +0000 | [diff] [blame] | 33 | |
| 34 | /* System headers include a number of constants from POSIX in <limits.h>. */ |
| 35 | #include_next <limits.h> |
| 36 | |
| 37 | /* Many system headers try to "help us out" by defining these. No really, we |
| 38 | know how big each datatype is. */ |
| 39 | #undef SCHAR_MIN |
| 40 | #undef SCHAR_MAX |
| 41 | #undef UCHAR_MAX |
| 42 | #undef SHRT_MIN |
| 43 | #undef SHRT_MAX |
| 44 | #undef USHRT_MAX |
| 45 | #undef INT_MIN |
| 46 | #undef INT_MAX |
| 47 | #undef UINT_MAX |
| 48 | #undef LONG_MIN |
| 49 | #undef LONG_MAX |
| 50 | #undef ULONG_MAX |
| 51 | |
| 52 | #undef MB_LEN_MAX |
| 53 | #undef CHAR_BIT |
| 54 | #undef CHAR_MIN |
| 55 | #undef CHAR_MAX |
| 56 | |
| 57 | /* C90/99 5.2.4.2.1 */ |
| 58 | #define SCHAR_MAX __SCHAR_MAX__ |
| 59 | #define SHRT_MAX __SHRT_MAX__ |
| 60 | #define INT_MAX __INT_MAX__ |
| 61 | #define LONG_MAX __LONG_MAX__ |
| 62 | |
| 63 | #define SCHAR_MIN (-__SCHAR_MAX__-1) |
| 64 | #define SHRT_MIN (-__SHRT_MAX__ -1) |
| 65 | #define INT_MIN (-__INT_MAX__ -1) |
| 66 | #define LONG_MIN (-__LONG_MAX__ -1L) |
| 67 | |
| 68 | #define UCHAR_MAX (__SCHAR_MAX__*2 +1) |
| 69 | #define USHRT_MAX (__SHRT_MAX__ *2 +1) |
| 70 | #define UINT_MAX (__INT_MAX__ *2U +1U) |
| 71 | #define ULONG_MAX (__LONG_MAX__ *2UL+1UL) |
| 72 | |
Chris Lattner | ed27d44 | 2009-02-06 23:29:39 +0000 | [diff] [blame] | 73 | #ifndef MB_LEN_MAX |
Chris Lattner | c807423 | 2009-02-06 18:34:27 +0000 | [diff] [blame] | 74 | #define MB_LEN_MAX 1 |
Chris Lattner | ed27d44 | 2009-02-06 23:29:39 +0000 | [diff] [blame] | 75 | #endif |
| 76 | |
Chris Lattner | c807423 | 2009-02-06 18:34:27 +0000 | [diff] [blame] | 77 | #define CHAR_BIT __CHAR_BIT__ |
| 78 | |
| 79 | #ifdef __CHAR_UNSIGNED__ /* -funsigned-char */ |
Chris Lattner | ed27d44 | 2009-02-06 23:29:39 +0000 | [diff] [blame] | 80 | #define CHAR_MIN 0 |
Chris Lattner | c807423 | 2009-02-06 18:34:27 +0000 | [diff] [blame] | 81 | #define CHAR_MAX UCHAR_MAX |
| 82 | #else |
| 83 | #define CHAR_MIN SCHAR_MIN |
| 84 | #define CHAR_MAX __SCHAR_MAX__ |
| 85 | #endif |
| 86 | |
| 87 | /* C99 5.2.4.2.1: Added long long. */ |
| 88 | #if __STDC_VERSION__ >= 199901 |
| 89 | |
| 90 | #undef LLONG_MIN |
| 91 | #undef LLONG_MAX |
| 92 | #undef ULLONG_MAX |
| 93 | |
| 94 | #define LLONG_MAX __LONG_LONG_MAX__ |
| 95 | #define LLONG_MIN (-__LONG_LONG_MAX__-1LL) |
| 96 | #define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL) |
| 97 | #endif |
| 98 | |
Chris Lattner | 2fc47b5 | 2009-04-01 00:44:37 +0000 | [diff] [blame] | 99 | /* LONG_LONG_MIN/LONG_LONG_MAX/ULONG_LONG_MAX are a GNU extension. It's too bad |
| 100 | that we don't have something like #pragma poison that could be used to |
| 101 | deprecate a macro - the code should just use LLONG_MAX and friends. |
| 102 | */ |
| 103 | #if defined(__GNU_LIBRARY__) ? defined(__USE_GNU) : !defined(__STRICT_ANSI__) |
| 104 | |
| 105 | #undef LONG_LONG_MIN |
| 106 | #undef LONG_LONG_MAX |
| 107 | #undef ULONG_LONG_MAX |
| 108 | |
| 109 | #define LONG_LONG_MAX __LONG_LONG_MAX__ |
| 110 | #define LONG_LONG_MIN (-__LONG_LONG_MAX__-1LL) |
| 111 | #define ULONG_LONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL) |
| 112 | #endif |
| 113 | |
Mike Stump | 3855b9a | 2009-02-12 23:06:31 +0000 | [diff] [blame] | 114 | #endif /* __CLANG_LIMITS_H */ |