inttypes.h
Go to the documentation of this file.
1 // ISO C9x compliant inttypes.h for Microsoft Visual Studio
2 // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
3 //
4 // Copyright (c) 2006-2013 Alexander Chemeris
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // 3. Neither the name of the product nor the names of its contributors may
17 // be used to endorse or promote products derived from this software
18 // without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
23 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 //
32 
33 // The above software in this distribution may have been modified by
34 // THL A29 Limited ("Tencent Modifications").
35 // All Tencent Modifications are Copyright (C) 2015 THL A29 Limited.
36 
37 #ifndef _MSC_VER // [
38 #error "Use this header only with Microsoft Visual C++ compilers!"
39 #endif // _MSC_VER ]
40 
41 #ifndef _MSC_INTTYPES_H_ // [
42 #define _MSC_INTTYPES_H_
43 
44 #if _MSC_VER > 1000
45 #pragma once
46 #endif
47 
48 #include "stdint.h"
49 
50 // miloyip: VC supports inttypes.h since VC2013
51 #if _MSC_VER >= 1800
52 #include <inttypes.h>
53 #else
54 
55 // 7.8 Format conversion of integer types
56 
57 typedef struct
58 {
61 } imaxdiv_t;
62 
63 // 7.8.1 Macros for format specifiers
64 
65 #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
66 
67 // The fprintf macros for signed integers are:
68 #define PRId8 "d"
69 #define PRIi8 "i"
70 #define PRIdLEAST8 "d"
71 #define PRIiLEAST8 "i"
72 #define PRIdFAST8 "d"
73 #define PRIiFAST8 "i"
74 
75 #define PRId16 "hd"
76 #define PRIi16 "hi"
77 #define PRIdLEAST16 "hd"
78 #define PRIiLEAST16 "hi"
79 #define PRIdFAST16 "hd"
80 #define PRIiFAST16 "hi"
81 
82 #define PRId32 "I32d"
83 #define PRIi32 "I32i"
84 #define PRIdLEAST32 "I32d"
85 #define PRIiLEAST32 "I32i"
86 #define PRIdFAST32 "I32d"
87 #define PRIiFAST32 "I32i"
88 
89 #define PRId64 "I64d"
90 #define PRIi64 "I64i"
91 #define PRIdLEAST64 "I64d"
92 #define PRIiLEAST64 "I64i"
93 #define PRIdFAST64 "I64d"
94 #define PRIiFAST64 "I64i"
95 
96 #define PRIdMAX "I64d"
97 #define PRIiMAX "I64i"
98 
99 #define PRIdPTR "Id"
100 #define PRIiPTR "Ii"
101 
102 // The fprintf macros for unsigned integers are:
103 #define PRIo8 "o"
104 #define PRIu8 "u"
105 #define PRIx8 "x"
106 #define PRIX8 "X"
107 #define PRIoLEAST8 "o"
108 #define PRIuLEAST8 "u"
109 #define PRIxLEAST8 "x"
110 #define PRIXLEAST8 "X"
111 #define PRIoFAST8 "o"
112 #define PRIuFAST8 "u"
113 #define PRIxFAST8 "x"
114 #define PRIXFAST8 "X"
115 
116 #define PRIo16 "ho"
117 #define PRIu16 "hu"
118 #define PRIx16 "hx"
119 #define PRIX16 "hX"
120 #define PRIoLEAST16 "ho"
121 #define PRIuLEAST16 "hu"
122 #define PRIxLEAST16 "hx"
123 #define PRIXLEAST16 "hX"
124 #define PRIoFAST16 "ho"
125 #define PRIuFAST16 "hu"
126 #define PRIxFAST16 "hx"
127 #define PRIXFAST16 "hX"
128 
129 #define PRIo32 "I32o"
130 #define PRIu32 "I32u"
131 #define PRIx32 "I32x"
132 #define PRIX32 "I32X"
133 #define PRIoLEAST32 "I32o"
134 #define PRIuLEAST32 "I32u"
135 #define PRIxLEAST32 "I32x"
136 #define PRIXLEAST32 "I32X"
137 #define PRIoFAST32 "I32o"
138 #define PRIuFAST32 "I32u"
139 #define PRIxFAST32 "I32x"
140 #define PRIXFAST32 "I32X"
141 
142 #define PRIo64 "I64o"
143 #define PRIu64 "I64u"
144 #define PRIx64 "I64x"
145 #define PRIX64 "I64X"
146 #define PRIoLEAST64 "I64o"
147 #define PRIuLEAST64 "I64u"
148 #define PRIxLEAST64 "I64x"
149 #define PRIXLEAST64 "I64X"
150 #define PRIoFAST64 "I64o"
151 #define PRIuFAST64 "I64u"
152 #define PRIxFAST64 "I64x"
153 #define PRIXFAST64 "I64X"
154 
155 #define PRIoMAX "I64o"
156 #define PRIuMAX "I64u"
157 #define PRIxMAX "I64x"
158 #define PRIXMAX "I64X"
159 
160 #define PRIoPTR "Io"
161 #define PRIuPTR "Iu"
162 #define PRIxPTR "Ix"
163 #define PRIXPTR "IX"
164 
165 // The fscanf macros for signed integers are:
166 #define SCNd8 "d"
167 #define SCNi8 "i"
168 #define SCNdLEAST8 "d"
169 #define SCNiLEAST8 "i"
170 #define SCNdFAST8 "d"
171 #define SCNiFAST8 "i"
172 
173 #define SCNd16 "hd"
174 #define SCNi16 "hi"
175 #define SCNdLEAST16 "hd"
176 #define SCNiLEAST16 "hi"
177 #define SCNdFAST16 "hd"
178 #define SCNiFAST16 "hi"
179 
180 #define SCNd32 "ld"
181 #define SCNi32 "li"
182 #define SCNdLEAST32 "ld"
183 #define SCNiLEAST32 "li"
184 #define SCNdFAST32 "ld"
185 #define SCNiFAST32 "li"
186 
187 #define SCNd64 "I64d"
188 #define SCNi64 "I64i"
189 #define SCNdLEAST64 "I64d"
190 #define SCNiLEAST64 "I64i"
191 #define SCNdFAST64 "I64d"
192 #define SCNiFAST64 "I64i"
193 
194 #define SCNdMAX "I64d"
195 #define SCNiMAX "I64i"
196 
197 #if _WIN64 // [
198 #define SCNdPTR "I64d"
199 #define SCNiPTR "I64i"
200 #else // _WIN64 ][
201 #define SCNdPTR "ld"
202 #define SCNiPTR "li"
203 #endif // _WIN64 ]
204 
205 // The fscanf macros for unsigned integers are:
206 #define SCNo8 "o"
207 #define SCNu8 "u"
208 #define SCNx8 "x"
209 #define SCNX8 "X"
210 #define SCNoLEAST8 "o"
211 #define SCNuLEAST8 "u"
212 #define SCNxLEAST8 "x"
213 #define SCNXLEAST8 "X"
214 #define SCNoFAST8 "o"
215 #define SCNuFAST8 "u"
216 #define SCNxFAST8 "x"
217 #define SCNXFAST8 "X"
218 
219 #define SCNo16 "ho"
220 #define SCNu16 "hu"
221 #define SCNx16 "hx"
222 #define SCNX16 "hX"
223 #define SCNoLEAST16 "ho"
224 #define SCNuLEAST16 "hu"
225 #define SCNxLEAST16 "hx"
226 #define SCNXLEAST16 "hX"
227 #define SCNoFAST16 "ho"
228 #define SCNuFAST16 "hu"
229 #define SCNxFAST16 "hx"
230 #define SCNXFAST16 "hX"
231 
232 #define SCNo32 "lo"
233 #define SCNu32 "lu"
234 #define SCNx32 "lx"
235 #define SCNX32 "lX"
236 #define SCNoLEAST32 "lo"
237 #define SCNuLEAST32 "lu"
238 #define SCNxLEAST32 "lx"
239 #define SCNXLEAST32 "lX"
240 #define SCNoFAST32 "lo"
241 #define SCNuFAST32 "lu"
242 #define SCNxFAST32 "lx"
243 #define SCNXFAST32 "lX"
244 
245 #define SCNo64 "I64o"
246 #define SCNu64 "I64u"
247 #define SCNx64 "I64x"
248 #define SCNX64 "I64X"
249 #define SCNoLEAST64 "I64o"
250 #define SCNuLEAST64 "I64u"
251 #define SCNxLEAST64 "I64x"
252 #define SCNXLEAST64 "I64X"
253 #define SCNoFAST64 "I64o"
254 #define SCNuFAST64 "I64u"
255 #define SCNxFAST64 "I64x"
256 #define SCNXFAST64 "I64X"
257 
258 #define SCNoMAX "I64o"
259 #define SCNuMAX "I64u"
260 #define SCNxMAX "I64x"
261 #define SCNXMAX "I64X"
262 
263 #if _WIN64 // [
264 #define SCNoPTR "I64o"
265 #define SCNuPTR "I64u"
266 #define SCNxPTR "I64x"
267 #define SCNXPTR "I64X"
268 #else // _WIN64 ][
269 #define SCNoPTR "lo"
270 #define SCNuPTR "lu"
271 #define SCNxPTR "lx"
272 #define SCNXPTR "lX"
273 #endif // _WIN64 ]
274 
275 #endif // __STDC_FORMAT_MACROS ]
276 
277 // 7.8.2 Functions for greatest-width integer types
278 
279 // 7.8.2.1 The imaxabs function
280 #define imaxabs _abs64
281 
282 // 7.8.2.2 The imaxdiv function
283 
284 // This is modified version of div() function from Microsoft's div.c found
285 // in %MSVC.NET%\crt\src\div.c
286 #if STATIC_IMAXDIV // [
287 static
288 #else // STATIC_IMAXDIV ][
289 _inline
290 #endif // STATIC_IMAXDIV ]
291  imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
292 {
293  imaxdiv_t result;
294 
295  result.quot = numer / denom;
296  result.rem = numer % denom;
297 
298  if (numer < 0 && result.rem > 0)
299  {
300  // did division wrong; must fix up
301  ++result.quot;
302  result.rem -= denom;
303  }
304 
305  return result;
306 }
307 
308 // 7.8.2.3 The strtoimax and strtoumax functions
309 #define strtoimax _strtoi64
310 #define strtoumax _strtoui64
311 
312 // 7.8.2.4 The wcstoimax and wcstoumax functions
313 #define wcstoimax _wcstoi64
314 #define wcstoumax _wcstoui64
315 
316 #endif // _MSC_VER >= 1800
317 
318 #endif // _MSC_INTTYPES_H_ ]
int64_t intmax_t
Definition: stdint.h:168
_inline imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
Definition: inttypes.h:291
intmax_t rem
Definition: inttypes.h:60
intmax_t quot
Definition: inttypes.h:59


xbot_talker
Author(s): wangxiaoyun
autogenerated on Sat Oct 10 2020 03:27:53