2 * Copyright (c) 2004, 2005 by
3 * Ralf Corsepius, Ulm/Germany. All rights reserved.
5 * Permission to use, copy, modify, and distribute this software
6 * is freely granted, provided that this notice is preserved.
12 #include <machine/_default_types.h>
13 #include <sys/_intsup.h>
14 #include <sys/_stdint.h>
20 #ifdef ___int_least8_t_defined
21 typedef __int_least8_t
int_least8_t;
22 typedef __uint_least8_t
uint_least8_t;
23 #define __int_least8_t_defined 1
26 #ifdef ___int_least16_t_defined
27 typedef __int_least16_t
int_least16_t;
28 typedef __uint_least16_t
uint_least16_t;
29 #define __int_least16_t_defined 1
32 #ifdef ___int_least32_t_defined
33 typedef __int_least32_t
int_least32_t;
34 typedef __uint_least32_t
uint_least32_t;
35 #define __int_least32_t_defined 1
38 #ifdef ___int_least64_t_defined
39 typedef __int_least64_t
int_least64_t;
40 typedef __uint_least64_t
uint_least64_t;
41 #define __int_least64_t_defined 1
45 * Fastest minimum-width integer types
47 * Assume int to be the fastest type for all types with a width
48 * less than __INT_MAX__ rsp. INT_MAX
50 #ifdef __INT_FAST8_TYPE__
51 typedef __INT_FAST8_TYPE__
int_fast8_t;
52 typedef __UINT_FAST8_TYPE__
uint_fast8_t;
53 #define __int_fast8_t_defined 1
54 #elif __STDINT_EXP(INT_MAX) >= 0x7f
55 typedef signed int int_fast8_t;
56 typedef unsigned int uint_fast8_t;
57 #define __int_fast8_t_defined 1
60 #ifdef __INT_FAST16_TYPE__
61 typedef __INT_FAST16_TYPE__
int_fast16_t;
62 typedef __UINT_FAST16_TYPE__
uint_fast16_t;
63 #define __int_fast16_t_defined 1
64 #elif __STDINT_EXP(INT_MAX) >= 0x7fff
65 typedef signed int int_fast16_t;
66 typedef unsigned int uint_fast16_t;
67 #define __int_fast16_t_defined 1
70 #ifdef __INT_FAST32_TYPE__
71 typedef __INT_FAST32_TYPE__
int_fast32_t;
72 typedef __UINT_FAST32_TYPE__
uint_fast32_t;
73 #define __int_fast32_t_defined 1
74 #elif __STDINT_EXP(INT_MAX) >= 0x7fffffff
75 typedef signed int int_fast32_t;
76 typedef unsigned int uint_fast32_t;
77 #define __int_fast32_t_defined 1
80 #ifdef __INT_FAST64_TYPE__
81 typedef __INT_FAST64_TYPE__
int_fast64_t;
82 typedef __UINT_FAST64_TYPE__
uint_fast64_t;
83 #define __int_fast64_t_defined 1
84 #elif __STDINT_EXP(INT_MAX) > 0x7fffffff
85 typedef signed int int_fast64_t;
86 typedef unsigned int uint_fast64_t;
87 #define __int_fast64_t_defined 1
91 * Fall back to [u]int_least<N>_t for [u]int_fast<N>_t types
92 * not having been defined, yet.
93 * Leave undefined, if [u]int_least<N>_t should not be available.
95 #if !__int_fast8_t_defined
96 #if __int_least8_t_defined
97 typedef int_least8_t int_fast8_t;
98 typedef uint_least8_t uint_fast8_t;
99 #define __int_fast8_t_defined 1
103 #if !__int_fast16_t_defined
104 #if __int_least16_t_defined
105 typedef int_least16_t int_fast16_t;
106 typedef uint_least16_t uint_fast16_t;
107 #define __int_fast16_t_defined 1
111 #if !__int_fast32_t_defined
112 #if __int_least32_t_defined
113 typedef int_least32_t int_fast32_t;
114 typedef uint_least32_t uint_fast32_t;
115 #define __int_fast32_t_defined 1
119 #if !__int_fast64_t_defined
120 #if __int_least64_t_defined
121 typedef int_least64_t int_fast64_t;
122 typedef uint_least64_t uint_fast64_t;
123 #define __int_fast64_t_defined 1
127 #ifdef __INTPTR_TYPE__
128 #define INTPTR_MIN (-__INTPTR_MAX__ - 1)
129 #define INTPTR_MAX (__INTPTR_MAX__)
130 #define UINTPTR_MAX (__UINTPTR_MAX__)
131 #elif defined(__PTRDIFF_TYPE__)
132 #define INTPTR_MAX PTRDIFF_MAX
133 #define INTPTR_MIN PTRDIFF_MIN
134 #ifdef __UINTPTR_MAX__
135 #define UINTPTR_MAX (__UINTPTR_MAX__)
137 #define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1)
141 * Fallback to hardcoded values,
142 * should be valid on cpu's with 32bit int/32bit void*
144 #define INTPTR_MAX (__STDINT_EXP(LONG_MAX))
145 #define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1)
146 #define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
149 /* Limits of Specified-Width Integer Types */
152 #define INT8_MIN (-__INT8_MAX__ - 1)
153 #define INT8_MAX (__INT8_MAX__)
154 #define UINT8_MAX (__UINT8_MAX__)
155 #elif defined(__int8_t_defined)
156 #define INT8_MIN (-128)
157 #define INT8_MAX (127)
158 #define UINT8_MAX (255)
161 #ifdef __INT_LEAST8_MAX__
162 #define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1)
163 #define INT_LEAST8_MAX (__INT_LEAST8_MAX__)
164 #define UINT_LEAST8_MAX (__UINT_LEAST8_MAX__)
165 #elif defined(__int_least8_t_defined)
166 #define INT_LEAST8_MIN (-128)
167 #define INT_LEAST8_MAX (127)
168 #define UINT_LEAST8_MAX (255)
170 #error required type int_least8_t missing
174 #define INT16_MIN (-__INT16_MAX__ - 1)
175 #define INT16_MAX (__INT16_MAX__)
176 #define UINT16_MAX (__UINT16_MAX__)
177 #elif defined(__int16_t_defined)
178 #define INT16_MIN (-32768)
179 #define INT16_MAX (32767)
180 #define UINT16_MAX (65535)
183 #ifdef __INT_LEAST16_MAX__
184 #define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1)
185 #define INT_LEAST16_MAX (__INT_LEAST16_MAX__)
186 #define UINT_LEAST16_MAX (__UINT_LEAST16_MAX__)
187 #elif defined(__int_least16_t_defined)
188 #define INT_LEAST16_MIN (-32768)
189 #define INT_LEAST16_MAX (32767)
190 #define UINT_LEAST16_MAX (65535)
192 #error required type int_least16_t missing
196 #define INT32_MIN (-__INT32_MAX__ - 1)
197 #define INT32_MAX (__INT32_MAX__)
198 #define UINT32_MAX (__UINT32_MAX__)
199 #elif defined(__int32_t_defined)
200 #if defined (_INT32_EQ_LONG)
201 #define INT32_MIN (-2147483647L-1)
202 #define INT32_MAX (2147483647L)
203 #define UINT32_MAX (4294967295UL)
205 #define INT32_MIN (-2147483647-1)
206 #define INT32_MAX (2147483647)
207 #define UINT32_MAX (4294967295U)
211 #ifdef __INT_LEAST32_MAX__
212 #define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1)
213 #define INT_LEAST32_MAX (__INT_LEAST32_MAX__)
214 #define UINT_LEAST32_MAX (__UINT_LEAST32_MAX__)
215 #elif defined(__int_least32_t_defined)
216 #if defined (_INT32_EQ_LONG)
217 #define INT_LEAST32_MIN (-2147483647L-1)
218 #define INT_LEAST32_MAX (2147483647L)
219 #define UINT_LEAST32_MAX (4294967295UL)
221 #define INT_LEAST32_MIN (-2147483647-1)
222 #define INT_LEAST32_MAX (2147483647)
223 #define UINT_LEAST32_MAX (4294967295U)
226 #error required type int_least32_t missing
230 #define INT64_MIN (-__INT64_MAX__ - 1)
231 #define INT64_MAX (__INT64_MAX__)
232 #define UINT64_MAX (__UINT64_MAX__)
233 #elif defined(__int64_t_defined)
235 #define INT64_MIN (-9223372036854775807L-1L)
236 #define INT64_MAX (9223372036854775807L)
237 #define UINT64_MAX (18446744073709551615U)
238 #elif __have_longlong64
239 #define INT64_MIN (-9223372036854775807LL-1LL)
240 #define INT64_MAX (9223372036854775807LL)
241 #define UINT64_MAX (18446744073709551615ULL)
245 #ifdef __INT_LEAST64_MAX__
246 #define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1)
247 #define INT_LEAST64_MAX (__INT_LEAST64_MAX__)
248 #define UINT_LEAST64_MAX (__UINT_LEAST64_MAX__)
249 #elif defined(__int_least64_t_defined)
251 #define INT_LEAST64_MIN (-9223372036854775807L-1L)
252 #define INT_LEAST64_MAX (9223372036854775807L)
253 #define UINT_LEAST64_MAX (18446744073709551615U)
254 #elif __have_longlong64
255 #define INT_LEAST64_MIN (-9223372036854775807LL-1LL)
256 #define INT_LEAST64_MAX (9223372036854775807LL)
257 #define UINT_LEAST64_MAX (18446744073709551615ULL)
261 #ifdef __INT_FAST8_MAX__
262 #define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1)
263 #define INT_FAST8_MAX (__INT_FAST8_MAX__)
264 #define UINT_FAST8_MAX (__UINT_FAST8_MAX__)
265 #elif defined(__int_fast8_t_defined)
266 #if __STDINT_EXP(INT_MAX) >= 0x7f
267 #define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX)-1)
268 #define INT_FAST8_MAX (__STDINT_EXP(INT_MAX))
269 #define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
271 #define INT_FAST8_MIN INT_LEAST8_MIN
272 #define INT_FAST8_MAX INT_LEAST8_MAX
273 #define UINT_FAST8_MAX UINT_LEAST8_MAX
277 #ifdef __INT_FAST16_MAX__
278 #define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1)
279 #define INT_FAST16_MAX (__INT_FAST16_MAX__)
280 #define UINT_FAST16_MAX (__UINT_FAST16_MAX__)
281 #elif defined(__int_fast16_t_defined)
282 #if __STDINT_EXP(INT_MAX) >= 0x7fff
283 #define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX)-1)
284 #define INT_FAST16_MAX (__STDINT_EXP(INT_MAX))
285 #define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
287 #define INT_FAST16_MIN INT_LEAST16_MIN
288 #define INT_FAST16_MAX INT_LEAST16_MAX
289 #define UINT_FAST16_MAX UINT_LEAST16_MAX
293 #ifdef __INT_FAST32_MAX__
294 #define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1)
295 #define INT_FAST32_MAX (__INT_FAST32_MAX__)
296 #define UINT_FAST32_MAX (__UINT_FAST32_MAX__)
297 #elif defined(__int_fast32_t_defined)
298 #if __STDINT_EXP(INT_MAX) >= 0x7fffffff
299 #define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX)-1)
300 #define INT_FAST32_MAX (__STDINT_EXP(INT_MAX))
301 #define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
303 #define INT_FAST32_MIN INT_LEAST32_MIN
304 #define INT_FAST32_MAX INT_LEAST32_MAX
305 #define UINT_FAST32_MAX UINT_LEAST32_MAX
309 #ifdef __INT_FAST64_MAX__
310 #define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1)
311 #define INT_FAST64_MAX (__INT_FAST64_MAX__)
312 #define UINT_FAST64_MAX (__UINT_FAST64_MAX__)
313 #elif defined(__int_fast64_t_defined)
314 #if __STDINT_EXP(INT_MAX) > 0x7fffffff
315 #define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX)-1)
316 #define INT_FAST64_MAX (__STDINT_EXP(INT_MAX))
317 #define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
319 #define INT_FAST64_MIN INT_LEAST64_MIN
320 #define INT_FAST64_MAX INT_LEAST64_MAX
321 #define UINT_FAST64_MAX UINT_LEAST64_MAX
325 #ifdef __INTMAX_MAX__
326 #define INTMAX_MAX (__INTMAX_MAX__)
327 #define INTMAX_MIN (-INTMAX_MAX - 1)
328 #elif defined(__INTMAX_TYPE__)
329 /* All relevant GCC versions prefer long to long long for intmax_t. */
330 #define INTMAX_MAX INT64_MAX
331 #define INTMAX_MIN INT64_MIN
334 #ifdef __UINTMAX_MAX__
335 #define UINTMAX_MAX (__UINTMAX_MAX__)
336 #elif defined(__UINTMAX_TYPE__)
337 /* All relevant GCC versions prefer long to long long for intmax_t. */
338 #define UINTMAX_MAX UINT64_MAX
341 /* This must match size_t in stddef.h, currently long unsigned int */
343 #define SIZE_MAX (__SIZE_MAX__)
345 #define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
348 /* This must match sig_atomic_t in <signal.h> (currently int) */
349 #define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1)
350 #define SIG_ATOMIC_MAX (__STDINT_EXP(INT_MAX))
352 /* This must match ptrdiff_t in <stddef.h> (currently long int) */
353 #ifdef __PTRDIFF_MAX__
354 #define PTRDIFF_MAX (__PTRDIFF_MAX__)
356 #define PTRDIFF_MAX (__STDINT_EXP(LONG_MAX))
358 #define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
360 /* This must match definition in <wchar.h> */
363 #define WCHAR_MIN (__WCHAR_MIN__)
364 #elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0)
365 #define WCHAR_MIN (0 + L'\0')
367 #define WCHAR_MIN (-0x7fffffff - 1 + L'\0')
371 /* This must match definition in <wchar.h> */
374 #define WCHAR_MAX (__WCHAR_MAX__)
375 #elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0)
376 #define WCHAR_MAX (0xffffffffu + L'\0')
378 #define WCHAR_MAX (0x7fffffff + L'\0')
382 /* wint_t is unsigned int on almost all GCC targets. */
384 #define WINT_MAX (__WINT_MAX__)
386 #define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U)
389 #define WINT_MIN (__WINT_MIN__)
391 #define WINT_MIN (0U)
394 /** Macros for minimum-width integer constant expressions */
396 #define INT8_C(x) __INT8_C(x)
397 #define UINT8_C(x) __UINT8_C(x)
400 #if __STDINT_EXP(INT_MAX) > 0x7f
403 #define UINT8_C(x) x##U
408 #define INT16_C(x) __INT16_C(x)
409 #define UINT16_C(x) __UINT16_C(x)
412 #if __STDINT_EXP(INT_MAX) > 0x7fff
413 #define UINT16_C(x) x
415 #define UINT16_C(x) x##U
420 #define INT32_C(x) __INT32_C(x)
421 #define UINT32_C(x) __UINT32_C(x)
423 #if defined (_INT32_EQ_LONG)
424 #define INT32_C(x) x##L
425 #define UINT32_C(x) x##UL
428 #define UINT32_C(x) x##U
433 #define INT64_C(x) __INT64_C(x)
434 #define UINT64_C(x) __UINT64_C(x)
436 #if __int64_t_defined
438 #define INT64_C(x) x##L
439 #define UINT64_C(x) x##UL
441 #define INT64_C(x) x##LL
442 #define UINT64_C(x) x##ULL
447 /** Macros for greatest-width integer constant expression */
449 #define INTMAX_C(x) __INTMAX_C(x)
450 #define UINTMAX_C(x) __UINTMAX_C(x)
453 #define INTMAX_C(x) x##L
454 #define UINTMAX_C(x) x##UL
456 #define INTMAX_C(x) x##LL
457 #define UINTMAX_C(x) x##ULL
466 #endif /* _STDINT_H */