2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file was originally part of the w64 mingw-runtime package.
6 /* ISO C9x 7.18 Integer types <stdint.h>
7 * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
9 * THIS SOFTWARE IS NOT COPYRIGHTED
11 * Contributor: Danny Smith <danny_r_smith_2001@yahoo.co.nz>
12 * Modified for libusb/MSVC: Pete Batard <pbatard@gmail.com>
14 * This source code is offered for use in the public domain. You may
15 * use, modify or distribute it freely.
17 * This code is distributed in the hope that it will be useful but
18 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
19 * DISCLAIMED. This includes but is not limited to warranties of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 #error This header should only be used with Microsoft compilers
32 #ifndef _INTPTR_T_DEFINED
33 #define _INTPTR_T_DEFINED
34 #ifndef __intptr_t_defined
35 #define __intptr_t_defined
38 typedef __int64
intptr_t;
42 #endif /* __intptr_t_defined */
43 #endif /* _INTPTR_T_DEFINED */
45 #ifndef _UINTPTR_T_DEFINED
46 #define _UINTPTR_T_DEFINED
47 #ifndef __uintptr_t_defined
48 #define __uintptr_t_defined
51 typedef unsigned __int64
uintptr_t;
53 typedef unsigned int uintptr_t;
55 #endif /* __uintptr_t_defined */
56 #endif /* _UINTPTR_T_DEFINED */
58 #ifndef _PTRDIFF_T_DEFINED
59 #define _PTRDIFF_T_DEFINED
64 typedef __int64
ptrdiff_t;
66 typedef int ptrdiff_t;
68 #endif /* _PTRDIFF_T_ */
69 #endif /* _PTRDIFF_T_DEFINED */
71 #ifndef _WCHAR_T_DEFINED
72 #define _WCHAR_T_DEFINED
74 typedef unsigned short wchar_t;
76 #endif /* _WCHAR_T_DEFINED */
78 #ifndef _WCTYPE_T_DEFINED
79 #define _WCTYPE_T_DEFINED
82 typedef unsigned short wint_t;
83 typedef unsigned short wctype_t;
85 #endif /* _WCTYPE_T_DEFINED */
87 /* 7.18.1.1 Exact-width integer types */
88 typedef __int8
int8_t;
89 typedef unsigned __int8
uint8_t;
90 typedef __int16
int16_t;
91 typedef unsigned __int16
uint16_t;
92 typedef __int32
int32_t;
93 typedef unsigned __int32
uint32_t;
94 typedef __int64
int64_t;
95 typedef unsigned __int64
uint64_t;
97 /* 7.18.1.2 Minimum-width integer types */
98 typedef signed char int_least8_t;
99 typedef unsigned char uint_least8_t;
100 typedef short int_least16_t;
101 typedef unsigned short uint_least16_t;
102 typedef int int_least32_t;
103 typedef unsigned uint_least32_t;
104 typedef __int64
int_least64_t;
105 typedef unsigned __int64
uint_least64_t;
107 /* 7.18.1.3 Fastest minimum-width integer types
108 * Not actually guaranteed to be fastest for all purposes
109 * Here we use the exact-width types for 8 and 16-bit ints.
111 typedef __int8
int_fast8_t;
112 typedef unsigned __int8
uint_fast8_t;
113 typedef __int16
int_fast16_t;
114 typedef unsigned __int16
uint_fast16_t;
115 typedef __int32
int_fast32_t;
116 typedef unsigned __int32
uint_fast32_t;
117 typedef __int64
int_fast64_t;
118 typedef unsigned __int64
uint_fast64_t;
120 /* 7.18.1.5 Greatest-width integer types */
121 typedef __int64
intmax_t;
122 typedef unsigned __int64
uintmax_t;
124 /* 7.18.2 Limits of specified-width integer types */
126 /* 7.18.2.1 Limits of exact-width integer types */
127 #define INT8_MIN (-128)
128 #define INT16_MIN (-32768)
129 #define INT32_MIN (-2147483647 - 1)
130 #define INT64_MIN (-9223372036854775807LL - 1)
133 #define INT16_MAX 32767
134 #define INT32_MAX 2147483647
135 #define INT64_MAX 9223372036854775807LL
137 #define UINT8_MAX 255
138 #define UINT16_MAX 65535
139 #define UINT32_MAX 0xffffffffU /* 4294967295U */
140 #define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
142 /* 7.18.2.2 Limits of minimum-width integer types */
143 #define INT_LEAST8_MIN INT8_MIN
144 #define INT_LEAST16_MIN INT16_MIN
145 #define INT_LEAST32_MIN INT32_MIN
146 #define INT_LEAST64_MIN INT64_MIN
148 #define INT_LEAST8_MAX INT8_MAX
149 #define INT_LEAST16_MAX INT16_MAX
150 #define INT_LEAST32_MAX INT32_MAX
151 #define INT_LEAST64_MAX INT64_MAX
153 #define UINT_LEAST8_MAX UINT8_MAX
154 #define UINT_LEAST16_MAX UINT16_MAX
155 #define UINT_LEAST32_MAX UINT32_MAX
156 #define UINT_LEAST64_MAX UINT64_MAX
158 /* 7.18.2.3 Limits of fastest minimum-width integer types */
159 #define INT_FAST8_MIN INT8_MIN
160 #define INT_FAST16_MIN INT16_MIN
161 #define INT_FAST32_MIN INT32_MIN
162 #define INT_FAST64_MIN INT64_MIN
164 #define INT_FAST8_MAX INT8_MAX
165 #define INT_FAST16_MAX INT16_MAX
166 #define INT_FAST32_MAX INT32_MAX
167 #define INT_FAST64_MAX INT64_MAX
169 #define UINT_FAST8_MAX UINT8_MAX
170 #define UINT_FAST16_MAX UINT16_MAX
171 #define UINT_FAST32_MAX UINT32_MAX
172 #define UINT_FAST64_MAX UINT64_MAX
174 /* 7.18.2.4 Limits of integer types capable of holding
177 #define INTPTR_MIN INT64_MIN
178 #define INTPTR_MAX INT64_MAX
179 #define UINTPTR_MAX UINT64_MAX
181 #define INTPTR_MIN INT32_MIN
182 #define INTPTR_MAX INT32_MAX
183 #define UINTPTR_MAX UINT32_MAX
186 /* 7.18.2.5 Limits of greatest-width integer types */
187 #define INTMAX_MIN INT64_MIN
188 #define INTMAX_MAX INT64_MAX
189 #define UINTMAX_MAX UINT64_MAX
191 /* 7.18.3 Limits of other integer types */
193 #define PTRDIFF_MIN INT64_MIN
194 #define PTRDIFF_MAX INT64_MAX
196 #define PTRDIFF_MIN INT32_MIN
197 #define PTRDIFF_MAX INT32_MAX
200 #define SIG_ATOMIC_MIN INT32_MIN
201 #define SIG_ATOMIC_MAX INT32_MAX
205 #define SIZE_MAX UINT64_MAX
207 #define SIZE_MAX UINT32_MAX
211 #ifndef WCHAR_MIN /* also in wchar.h */
213 #define WCHAR_MAX 0xffffU
217 * wint_t is unsigned short for compatibility with MS runtime
220 #define WINT_MAX 0xffffU
223 /* 7.18.4 Macros for integer constants */
225 /* 7.18.4.1 Macros for minimum-width integer constants
227 Accoding to Douglas Gwyn <gwyn@arl.mil>:
228 "This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
229 9899:1999 as initially published, the expansion was required
230 to be an integer constant of precisely matching type, which
231 is impossible to accomplish for the shorter types on most
232 platforms, because C99 provides no standard way to designate
233 an integer constant with width less than that of type int.
234 TC1 changed this to require just an integer constant
235 *expression* with *promoted* type."
237 The trick used here is from Clive D W Feather.
240 #define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val))
241 #define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val))
242 #define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val))
243 /* The 'trick' doesn't work in C89 for long long because, without
244 suffix, (val) will be evaluated as int, not intmax_t */
245 #define INT64_C(val) val##i64
247 #define UINT8_C(val) (val)
248 #define UINT16_C(val) (val)
249 #define UINT32_C(val) (val##i32)
250 #define UINT64_C(val) val##ui64
252 /* 7.18.4.2 Macros for greatest-width integer constants */
253 #define INTMAX_C(val) val##i64
254 #define UINTMAX_C(val) val##ui64