]> git.saurik.com Git - apple/libc.git/blob - include/stdint.h
Libc-1353.11.2.tar.gz
[apple/libc.git] / include / stdint.h
1 /*
2 * Copyright (c) 2000-2010 Apple Inc.
3 * All rights reserved.
4 */
5
6 #ifndef _STDINT_H_
7 #define _STDINT_H_
8
9 #if __LP64__
10 #define __WORDSIZE 64
11 #else
12 #define __WORDSIZE 32
13 #endif
14
15 /* from ISO/IEC 988:1999 spec */
16
17 /* 7.18.1.1 Exact-width integer types */
18 #include <sys/_types/_int8_t.h>
19 #include <sys/_types/_int16_t.h>
20 #include <sys/_types/_int32_t.h>
21 #include <sys/_types/_int64_t.h>
22
23 #include <_types/_uint8_t.h>
24 #include <_types/_uint16_t.h>
25 #include <_types/_uint32_t.h>
26 #include <_types/_uint64_t.h>
27
28 /* 7.18.1.2 Minimum-width integer types */
29 typedef int8_t int_least8_t;
30 typedef int16_t int_least16_t;
31 typedef int32_t int_least32_t;
32 typedef int64_t int_least64_t;
33 typedef uint8_t uint_least8_t;
34 typedef uint16_t uint_least16_t;
35 typedef uint32_t uint_least32_t;
36 typedef uint64_t uint_least64_t;
37
38
39 /* 7.18.1.3 Fastest-width integer types */
40 typedef int8_t int_fast8_t;
41 typedef int16_t int_fast16_t;
42 typedef int32_t int_fast32_t;
43 typedef int64_t int_fast64_t;
44 typedef uint8_t uint_fast8_t;
45 typedef uint16_t uint_fast16_t;
46 typedef uint32_t uint_fast32_t;
47 typedef uint64_t uint_fast64_t;
48
49
50 /* 7.18.1.4 Integer types capable of holding object pointers */
51
52 #include <sys/_types.h>
53 #include <sys/_types/_intptr_t.h>
54 #include <sys/_types/_uintptr_t.h>
55
56
57 /* 7.18.1.5 Greatest-width integer types */
58 #include <_types/_intmax_t.h>
59 #include <_types/_uintmax_t.h>
60
61 /* 7.18.4 Macros for integer constants */
62 #define INT8_C(v) (v)
63 #define INT16_C(v) (v)
64 #define INT32_C(v) (v)
65 #define INT64_C(v) (v ## LL)
66
67 #define UINT8_C(v) (v)
68 #define UINT16_C(v) (v)
69 #define UINT32_C(v) (v ## U)
70 #define UINT64_C(v) (v ## ULL)
71
72 #ifdef __LP64__
73 #define INTMAX_C(v) (v ## L)
74 #define UINTMAX_C(v) (v ## UL)
75 #else
76 #define INTMAX_C(v) (v ## LL)
77 #define UINTMAX_C(v) (v ## ULL)
78 #endif
79
80 /* 7.18.2 Limits of specified-width integer types:
81 * These #defines specify the minimum and maximum limits
82 * of each of the types declared above.
83 *
84 * They must have "the same type as would an expression that is an
85 * object of the corresponding type converted according to the integer
86 * promotion".
87 */
88
89
90 /* 7.18.2.1 Limits of exact-width integer types */
91 #define INT8_MAX 127
92 #define INT16_MAX 32767
93 #define INT32_MAX 2147483647
94 #define INT64_MAX 9223372036854775807LL
95
96 #define INT8_MIN -128
97 #define INT16_MIN -32768
98 /*
99 Note: the literal "most negative int" cannot be written in C --
100 the rules in the standard (section 6.4.4.1 in C99) will give it
101 an unsigned type, so INT32_MIN (and the most negative member of
102 any larger signed type) must be written via a constant expression.
103 */
104 #define INT32_MIN (-INT32_MAX-1)
105 #define INT64_MIN (-INT64_MAX-1)
106
107 #define UINT8_MAX 255
108 #define UINT16_MAX 65535
109 #define UINT32_MAX 4294967295U
110 #define UINT64_MAX 18446744073709551615ULL
111
112 /* 7.18.2.2 Limits of minimum-width integer types */
113 #define INT_LEAST8_MIN INT8_MIN
114 #define INT_LEAST16_MIN INT16_MIN
115 #define INT_LEAST32_MIN INT32_MIN
116 #define INT_LEAST64_MIN INT64_MIN
117
118 #define INT_LEAST8_MAX INT8_MAX
119 #define INT_LEAST16_MAX INT16_MAX
120 #define INT_LEAST32_MAX INT32_MAX
121 #define INT_LEAST64_MAX INT64_MAX
122
123 #define UINT_LEAST8_MAX UINT8_MAX
124 #define UINT_LEAST16_MAX UINT16_MAX
125 #define UINT_LEAST32_MAX UINT32_MAX
126 #define UINT_LEAST64_MAX UINT64_MAX
127
128 /* 7.18.2.3 Limits of fastest minimum-width integer types */
129 #define INT_FAST8_MIN INT8_MIN
130 #define INT_FAST16_MIN INT16_MIN
131 #define INT_FAST32_MIN INT32_MIN
132 #define INT_FAST64_MIN INT64_MIN
133
134 #define INT_FAST8_MAX INT8_MAX
135 #define INT_FAST16_MAX INT16_MAX
136 #define INT_FAST32_MAX INT32_MAX
137 #define INT_FAST64_MAX INT64_MAX
138
139 #define UINT_FAST8_MAX UINT8_MAX
140 #define UINT_FAST16_MAX UINT16_MAX
141 #define UINT_FAST32_MAX UINT32_MAX
142 #define UINT_FAST64_MAX UINT64_MAX
143
144 /* 7.18.2.4 Limits of integer types capable of holding object pointers */
145
146 #if __WORDSIZE == 64
147 #define INTPTR_MAX 9223372036854775807L
148 #else
149 #define INTPTR_MAX 2147483647L
150 #endif
151 #define INTPTR_MIN (-INTPTR_MAX-1)
152
153 #if __WORDSIZE == 64
154 #define UINTPTR_MAX 18446744073709551615UL
155 #else
156 #define UINTPTR_MAX 4294967295UL
157 #endif
158
159 /* 7.18.2.5 Limits of greatest-width integer types */
160 #define INTMAX_MAX INTMAX_C(9223372036854775807)
161 #define UINTMAX_MAX UINTMAX_C(18446744073709551615)
162 #define INTMAX_MIN (-INTMAX_MAX-1)
163
164 /* 7.18.3 "Other" */
165 #if __WORDSIZE == 64
166 #define PTRDIFF_MIN INTMAX_MIN
167 #define PTRDIFF_MAX INTMAX_MAX
168 #else
169 #define PTRDIFF_MIN INT32_MIN
170 #define PTRDIFF_MAX INT32_MAX
171 #endif
172
173 #define SIZE_MAX UINTPTR_MAX
174
175 #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
176 #define RSIZE_MAX (SIZE_MAX >> 1)
177 #endif
178
179 #ifndef WCHAR_MAX
180 # ifdef __WCHAR_MAX__
181 # define WCHAR_MAX __WCHAR_MAX__
182 # else
183 # define WCHAR_MAX 0x7fffffff
184 # endif
185 #endif
186
187 /* WCHAR_MIN should be 0 if wchar_t is an unsigned type and
188 (-WCHAR_MAX-1) if wchar_t is a signed type. Unfortunately,
189 it turns out that -fshort-wchar changes the signedness of
190 the type. */
191 #ifndef WCHAR_MIN
192 # if WCHAR_MAX == 0xffff
193 # define WCHAR_MIN 0
194 # else
195 # define WCHAR_MIN (-WCHAR_MAX-1)
196 # endif
197 #endif
198
199 #define WINT_MIN INT32_MIN
200 #define WINT_MAX INT32_MAX
201
202 #define SIG_ATOMIC_MIN INT32_MIN
203 #define SIG_ATOMIC_MAX INT32_MAX
204
205 #endif /* _STDINT_H_ */