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