• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
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.
4  */
5 
6 /* ISO C9x  7.18  Integer types <stdint.h>
7  * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
8  *
9  *  THIS SOFTWARE IS NOT COPYRIGHTED
10  *
11  *  Contributor: Danny Smith <danny_r_smith_2001@yahoo.co.nz>
12  *  Modified for libusb/MSVC: Pete Batard <pbatard@gmail.com>
13  *
14  *  This source code is offered for use in the public domain. You may
15  *  use, modify or distribute it freely.
16  *
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.
21  *
22  *  Date: 2010-04-02
23  */
24 
25 #ifndef _MSC_VER
26 #error This header should only be used with Microsoft compilers
27 #endif
28 
29 #ifndef _STDINT_H
30 #define _STDINT_H
31 
32 #ifndef _INTPTR_T_DEFINED
33 #define _INTPTR_T_DEFINED
34 #ifndef __intptr_t_defined
35 #define __intptr_t_defined
36 #undef intptr_t
37 #ifdef _WIN64
38   typedef __int64 intptr_t;
39 #else
40   typedef int intptr_t;
41 #endif /* _WIN64 */
42 #endif /* __intptr_t_defined */
43 #endif /* _INTPTR_T_DEFINED */
44 
45 #ifndef _UINTPTR_T_DEFINED
46 #define _UINTPTR_T_DEFINED
47 #ifndef __uintptr_t_defined
48 #define __uintptr_t_defined
49 #undef uintptr_t
50 #ifdef _WIN64
51   typedef unsigned __int64 uintptr_t;
52 #else
53   typedef unsigned int uintptr_t;
54 #endif /* _WIN64 */
55 #endif /* __uintptr_t_defined */
56 #endif /* _UINTPTR_T_DEFINED */
57 
58 #ifndef _PTRDIFF_T_DEFINED
59 #define _PTRDIFF_T_DEFINED
60 #ifndef _PTRDIFF_T_
61 #define _PTRDIFF_T_
62 #undef ptrdiff_t
63 #ifdef _WIN64
64   typedef __int64 ptrdiff_t;
65 #else
66   typedef int ptrdiff_t;
67 #endif /* _WIN64 */
68 #endif /* _PTRDIFF_T_ */
69 #endif /* _PTRDIFF_T_DEFINED */
70 
71 #ifndef _WCHAR_T_DEFINED
72 #define _WCHAR_T_DEFINED
73 #ifndef __cplusplus
74   typedef unsigned short wchar_t;
75 #endif /* C++ */
76 #endif /* _WCHAR_T_DEFINED */
77 
78 #ifndef _WCTYPE_T_DEFINED
79 #define _WCTYPE_T_DEFINED
80 #ifndef _WINT_T
81 #define _WINT_T
82   typedef unsigned short wint_t;
83   typedef unsigned short wctype_t;
84 #endif /* _WINT_T */
85 #endif /* _WCTYPE_T_DEFINED */
86 
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;
96 
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;
106 
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.
110  */
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;
119 
120 /* 7.18.1.5  Greatest-width integer types */
121 typedef __int64  intmax_t;
122 typedef unsigned __int64   uintmax_t;
123 
124 /* 7.18.2  Limits of specified-width integer types */
125 
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)
131 
132 #define INT8_MAX 127
133 #define INT16_MAX 32767
134 #define INT32_MAX 2147483647
135 #define INT64_MAX 9223372036854775807LL
136 
137 #define UINT8_MAX 255
138 #define UINT16_MAX 65535
139 #define UINT32_MAX 0xffffffffU  /* 4294967295U */
140 #define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
141 
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
147 
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
152 
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
157 
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
163 
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
168 
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
173 
174 /* 7.18.2.4  Limits of integer types capable of holding
175     object pointers */
176 #ifdef _WIN64
177 #define INTPTR_MIN INT64_MIN
178 #define INTPTR_MAX INT64_MAX
179 #define UINTPTR_MAX UINT64_MAX
180 #else
181 #define INTPTR_MIN INT32_MIN
182 #define INTPTR_MAX INT32_MAX
183 #define UINTPTR_MAX UINT32_MAX
184 #endif
185 
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
190 
191 /* 7.18.3  Limits of other integer types */
192 #ifdef _WIN64
193 #define PTRDIFF_MIN INT64_MIN
194 #define PTRDIFF_MAX INT64_MAX
195 #else
196 #define PTRDIFF_MIN INT32_MIN
197 #define PTRDIFF_MAX INT32_MAX
198 #endif
199 
200 #define SIG_ATOMIC_MIN INT32_MIN
201 #define SIG_ATOMIC_MAX INT32_MAX
202 
203 #ifndef SIZE_MAX
204 #ifdef _WIN64
205 #define SIZE_MAX UINT64_MAX
206 #else
207 #define SIZE_MAX UINT32_MAX
208 #endif
209 #endif
210 
211 #ifndef WCHAR_MIN  /* also in wchar.h */
212 #define WCHAR_MIN 0U
213 #define WCHAR_MAX 0xffffU
214 #endif
215 
216 /*
217  * wint_t is unsigned short for compatibility with MS runtime
218  */
219 #define WINT_MIN 0U
220 #define WINT_MAX 0xffffU
221 
222 
223 /* 7.18.4  Macros for integer constants */
224 
225 /* 7.18.4.1  Macros for minimum-width integer constants
226 
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."
236 
237 	The trick used here is from Clive D W Feather.
238 */
239 
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
246 
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
251 
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
255 
256 #endif
257