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