blob: 2e0deaff52f35beaa9840ea238a55514e79938f9 [file] [log] [blame]
Chris Lattnera9cece62009-02-06 18:45:59 +00001/*===---- limits.h - Standard header for integer sizes --------------------===*\
Chris Lattnerc8074232009-02-06 18:34:27 +00002 *
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 Lattner2a67f7b2009-02-06 22:59:47 +000023\*===----------------------------------------------------------------------===*/
Chris Lattnerc8074232009-02-06 18:34:27 +000024
25#ifndef __LIMITS_H
26#define __LIMITS_H
27
28/* System headers include a number of constants from POSIX in <limits.h>. */
29#include_next <limits.h>
30
31/* Many system headers try to "help us out" by defining these. No really, we
32 know how big each datatype is. */
33#undef SCHAR_MIN
34#undef SCHAR_MAX
35#undef UCHAR_MAX
36#undef SHRT_MIN
37#undef SHRT_MAX
38#undef USHRT_MAX
39#undef INT_MIN
40#undef INT_MAX
41#undef UINT_MAX
42#undef LONG_MIN
43#undef LONG_MAX
44#undef ULONG_MAX
45
46#undef MB_LEN_MAX
47#undef CHAR_BIT
48#undef CHAR_MIN
49#undef CHAR_MAX
50
51/* C90/99 5.2.4.2.1 */
52#define SCHAR_MAX __SCHAR_MAX__
53#define SHRT_MAX __SHRT_MAX__
54#define INT_MAX __INT_MAX__
55#define LONG_MAX __LONG_MAX__
56
57#define SCHAR_MIN (-__SCHAR_MAX__-1)
58#define SHRT_MIN (-__SHRT_MAX__ -1)
59#define INT_MIN (-__INT_MAX__ -1)
60#define LONG_MIN (-__LONG_MAX__ -1L)
61
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
Chris Lattnered27d442009-02-06 23:29:39 +000067#ifndef MB_LEN_MAX
Chris Lattnerc8074232009-02-06 18:34:27 +000068#define MB_LEN_MAX 1
Chris Lattnered27d442009-02-06 23:29:39 +000069#endif
70
Chris Lattnerc8074232009-02-06 18:34:27 +000071#define CHAR_BIT __CHAR_BIT__
72
73#ifdef __CHAR_UNSIGNED__ /* -funsigned-char */
Chris Lattnered27d442009-02-06 23:29:39 +000074#define CHAR_MIN 0
Chris Lattnerc8074232009-02-06 18:34:27 +000075#define CHAR_MAX UCHAR_MAX
76#else
77#define CHAR_MIN SCHAR_MIN
78#define CHAR_MAX __SCHAR_MAX__
79#endif
80
81/* C99 5.2.4.2.1: Added long long. */
82#if __STDC_VERSION__ >= 199901
83
84#undef LLONG_MIN
85#undef LLONG_MAX
86#undef ULLONG_MAX
87
88#define LLONG_MAX __LONG_LONG_MAX__
89#define LLONG_MIN (-__LONG_LONG_MAX__-1LL)
90#define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
91#endif
92
93#endif /* __LIMITS_H */