]> git.saurik.com Git - apple/libc.git/blob - include/stdint.h
a9e312d3b6d3e4a5f72a60a2bf102bd8cc1b32fe
[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 #ifndef _INT8_T
19 #define _INT8_T
20 typedef signed char int8_t;
21 #endif /*_INT8_T */
22
23 #ifndef _INT16_T
24 #define _INT16_T
25 typedef short int16_t;
26 #endif /* _INT16_T */
27
28 #ifndef _INT32_T
29 #define _INT32_T
30 typedef int int32_t;
31 #endif /* _INT32_T */
32
33 #ifndef _INT64_T
34 #define _INT64_T
35 typedef long long int64_t;
36 #endif /* _INT64_T */
37
38 #ifndef _UINT8_T
39 #define _UINT8_T
40 typedef unsigned char uint8_t;
41 #endif /*_UINT8_T */
42
43 #ifndef _UINT16_T
44 #define _UINT16_T
45 typedef unsigned short uint16_t;
46 #endif /* _UINT16_T */
47
48 #ifndef _UINT32_T
49 #define _UINT32_T
50 typedef unsigned int uint32_t;
51 #endif /* _UINT32_T */
52
53 #ifndef _UINT64_T
54 #define _UINT64_T
55 typedef unsigned long long uint64_t;
56 #endif /* _UINT64_T */
57
58 /* 7.18.1.2 Minimum-width integer types */
59 typedef int8_t int_least8_t;
60 typedef int16_t int_least16_t;
61 typedef int32_t int_least32_t;
62 typedef int64_t int_least64_t;
63 typedef uint8_t uint_least8_t;
64 typedef uint16_t uint_least16_t;
65 typedef uint32_t uint_least32_t;
66 typedef uint64_t uint_least64_t;
67
68
69 /* 7.18.1.3 Fastest-width integer types */
70 typedef int8_t int_fast8_t;
71 typedef int16_t int_fast16_t;
72 typedef int32_t int_fast32_t;
73 typedef int64_t int_fast64_t;
74 typedef uint8_t uint_fast8_t;
75 typedef uint16_t uint_fast16_t;
76 typedef uint32_t uint_fast32_t;
77 typedef uint64_t uint_fast64_t;
78
79
80 /* 7.18.1.4 Integer types capable of holding object pointers */
81
82 #ifndef _INTPTR_T
83 #define _INTPTR_T
84 typedef long intptr_t;
85 #endif /* _INTPTR_T */
86
87 #ifndef _UINTPTR_T
88 #define _UINTPTR_T
89 typedef unsigned long uintptr_t;
90 #endif /* _UINTPTR_T */
91
92
93 /* 7.18.1.5 Greatest-width integer types */
94 #ifndef _INTMAX_T
95 #define _INTMAX_T
96 #ifdef __INTMAX_TYPE__
97 typedef __INTMAX_TYPE__ intmax_t;
98 #else /* __INTMAX_TYPE__ */
99 typedef long long intmax_t;
100 #endif /* __INTMAX_TYPE__ */
101 #endif /* _INTMAX_T */
102
103 #ifndef _UINTMAX_T
104 #define _UINTMAX_T
105 #ifdef __UINTMAX_TYPE__
106 typedef __UINTMAX_TYPE__ uintmax_t;
107 #else /* __UINTMAX_TYPE__ */
108 typedef unsigned long long uintmax_t;
109 #endif /* __UINTMAX_TYPE__ */
110 #endif /* _UINTMAX_T */
111
112 /* 7.18.2 Limits of specified-width integer types:
113 * These #defines specify the minimum and maximum limits
114 * of each of the types declared above.
115 */
116
117
118 /* 7.18.2.1 Limits of exact-width integer types */
119 #define INT8_MAX 127
120 #define INT16_MAX 32767
121 #define INT32_MAX 2147483647
122 #define INT64_MAX 9223372036854775807LL
123
124 #define INT8_MIN -128
125 #define INT16_MIN -32768
126 /*
127 Note: the literal "most negative int" cannot be written in C --
128 the rules in the standard (section 6.4.4.1 in C99) will give it
129 an unsigned type, so INT32_MIN (and the most negative member of
130 any larger signed type) must be written via a constant expression.
131 */
132 #define INT32_MIN (-INT32_MAX-1)
133 #define INT64_MIN (-INT64_MAX-1)
134
135 #define UINT8_MAX 255
136 #define UINT16_MAX 65535
137 #define UINT32_MAX 4294967295U
138 #define UINT64_MAX 18446744073709551615ULL
139
140 /* 7.18.2.2 Limits of minimum-width integer types */
141 #define INT_LEAST8_MIN INT8_MIN
142 #define INT_LEAST16_MIN INT16_MIN
143 #define INT_LEAST32_MIN INT32_MIN
144 #define INT_LEAST64_MIN INT64_MIN
145
146 #define INT_LEAST8_MAX INT8_MAX
147 #define INT_LEAST16_MAX INT16_MAX
148 #define INT_LEAST32_MAX INT32_MAX
149 #define INT_LEAST64_MAX INT64_MAX
150
151 #define UINT_LEAST8_MAX UINT8_MAX
152 #define UINT_LEAST16_MAX UINT16_MAX
153 #define UINT_LEAST32_MAX UINT32_MAX
154 #define UINT_LEAST64_MAX UINT64_MAX
155
156 /* 7.18.2.3 Limits of fastest minimum-width integer types */
157 #define INT_FAST8_MIN INT8_MIN
158 #define INT_FAST16_MIN INT16_MIN
159 #define INT_FAST32_MIN INT32_MIN
160 #define INT_FAST64_MIN INT64_MIN
161
162 #define INT_FAST8_MAX INT8_MAX
163 #define INT_FAST16_MAX INT16_MAX
164 #define INT_FAST32_MAX INT32_MAX
165 #define INT_FAST64_MAX INT64_MAX
166
167 #define UINT_FAST8_MAX UINT8_MAX
168 #define UINT_FAST16_MAX UINT16_MAX
169 #define UINT_FAST32_MAX UINT32_MAX
170 #define UINT_FAST64_MAX UINT64_MAX
171
172 /* 7.18.2.4 Limits of integer types capable of holding object pointers */
173
174 #if __WORDSIZE == 64
175 #define INTPTR_MIN INT64_MIN
176 #define INTPTR_MAX INT64_MAX
177 #else
178 #define INTPTR_MIN INT32_MIN
179 #define INTPTR_MAX INT32_MAX
180 #endif
181
182 #if __WORDSIZE == 64
183 #define UINTPTR_MAX UINT64_MAX
184 #else
185 #define UINTPTR_MAX UINT32_MAX
186 #endif
187
188 /* 7.18.2.5 Limits of greatest-width integer types */
189 #define INTMAX_MIN INT64_MIN
190 #define INTMAX_MAX INT64_MAX
191
192 #define UINTMAX_MAX UINT64_MAX
193
194 /* 7.18.3 "Other" */
195 #if __WORDSIZE == 64
196 #define PTRDIFF_MIN INT64_MIN
197 #define PTRDIFF_MAX INT64_MAX
198 #else
199 #define PTRDIFF_MIN INT32_MIN
200 #define PTRDIFF_MAX INT32_MAX
201 #endif
202
203 /* We have no sig_atomic_t yet, so no SIG_ATOMIC_{MIN,MAX}.
204 Should end up being {-127,127} or {0,255} ... or bigger.
205 My bet would be on one of {U}INT32_{MIN,MAX}. */
206
207 #if __WORDSIZE == 64
208 #define SIZE_MAX UINT64_MAX
209 #else
210 #define SIZE_MAX UINT32_MAX
211 #endif
212
213 #ifndef WCHAR_MAX
214 # ifdef __WCHAR_MAX__
215 # define WCHAR_MAX __WCHAR_MAX__
216 # else
217 # define WCHAR_MAX 0x7fffffff
218 # endif
219 #endif
220
221 /* WCHAR_MIN should be 0 if wchar_t is an unsigned type and
222 (-WCHAR_MAX-1) if wchar_t is a signed type. Unfortunately,
223 it turns out that -fshort-wchar changes the signedness of
224 the type. */
225 #ifndef WCHAR_MIN
226 # if WCHAR_MAX == 0xffff
227 # define WCHAR_MIN 0
228 # else
229 # define WCHAR_MIN (-WCHAR_MAX-1)
230 # endif
231 #endif
232
233 #define WINT_MIN INT32_MIN
234 #define WINT_MAX INT32_MAX
235
236 #define SIG_ATOMIC_MIN INT32_MIN
237 #define SIG_ATOMIC_MAX INT32_MAX
238
239 /* 7.18.4 Macros for integer constants */
240 #define INT8_C(v) (v)
241 #define INT16_C(v) (v)
242 #define INT32_C(v) (v)
243 #define INT64_C(v) (v ## LL)
244
245 #define UINT8_C(v) (v ## U)
246 #define UINT16_C(v) (v ## U)
247 #define UINT32_C(v) (v ## U)
248 #define UINT64_C(v) (v ## ULL)
249
250 #define INTMAX_C(v) (v ## LL)
251 #define UINTMAX_C(v) (v ## ULL)
252
253 #endif /* _STDINT_H_ */