1 // ISO C9x compliant inttypes.h for Microsoft Visual Studio
2 // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
4 // Copyright (c) 2006 Alexander Chemeris
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // 1. Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
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.
16 // 3. The name of the author may be used to endorse or promote products
17 // derived from this software without specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
22 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ///////////////////////////////////////////////////////////////////////////////
33 #error "Use this header only with Microsoft Visual C++ compilers!"
36 // Modern Visual Studio has sane inttypes.h
39 #define _MSC_INTTYPES_H_
42 #ifndef _MSC_INTTYPES_H_ // [
43 #define _MSC_INTTYPES_H_
49 #include "stdint-win.h"
51 // 7.8 Format conversion of integer types
58 // 7.8.1 Macros for format specifiers
60 #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
62 // The fprintf macros for signed integers are:
65 #define PRIdLEAST8 "d"
66 #define PRIiLEAST8 "i"
72 #define PRIdLEAST16 "hd"
73 #define PRIiLEAST16 "hi"
74 #define PRIdFAST16 "hd"
75 #define PRIiFAST16 "hi"
79 #define PRIdLEAST32 "I32d"
80 #define PRIiLEAST32 "I32i"
81 #define PRIdFAST32 "I32d"
82 #define PRIiFAST32 "I32i"
86 #define PRIdLEAST64 "I64d"
87 #define PRIiLEAST64 "I64i"
88 #define PRIdFAST64 "I64d"
89 #define PRIiFAST64 "I64i"
91 #define PRIdMAX "I64d"
92 #define PRIiMAX "I64i"
97 // The fprintf macros for unsigned integers are:
102 #define PRIoLEAST8 "o"
103 #define PRIuLEAST8 "u"
104 #define PRIxLEAST8 "x"
105 #define PRIXLEAST8 "X"
106 #define PRIoFAST8 "o"
107 #define PRIuFAST8 "u"
108 #define PRIxFAST8 "x"
109 #define PRIXFAST8 "X"
115 #define PRIoLEAST16 "ho"
116 #define PRIuLEAST16 "hu"
117 #define PRIxLEAST16 "hx"
118 #define PRIXLEAST16 "hX"
119 #define PRIoFAST16 "ho"
120 #define PRIuFAST16 "hu"
121 #define PRIxFAST16 "hx"
122 #define PRIXFAST16 "hX"
124 #define PRIo32 "I32o"
125 #define PRIu32 "I32u"
126 #define PRIx32 "I32x"
127 #define PRIX32 "I32X"
128 #define PRIoLEAST32 "I32o"
129 #define PRIuLEAST32 "I32u"
130 #define PRIxLEAST32 "I32x"
131 #define PRIXLEAST32 "I32X"
132 #define PRIoFAST32 "I32o"
133 #define PRIuFAST32 "I32u"
134 #define PRIxFAST32 "I32x"
135 #define PRIXFAST32 "I32X"
137 #define PRIo64 "I64o"
138 #define PRIu64 "I64u"
139 #define PRIx64 "I64x"
140 #define PRIX64 "I64X"
141 #define PRIoLEAST64 "I64o"
142 #define PRIuLEAST64 "I64u"
143 #define PRIxLEAST64 "I64x"
144 #define PRIXLEAST64 "I64X"
145 #define PRIoFAST64 "I64o"
146 #define PRIuFAST64 "I64u"
147 #define PRIxFAST64 "I64x"
148 #define PRIXFAST64 "I64X"
150 #define PRIoMAX "I64o"
151 #define PRIuMAX "I64u"
152 #define PRIxMAX "I64x"
153 #define PRIXMAX "I64X"
160 // The fscanf macros for signed integers are:
163 #define SCNdLEAST8 "d"
164 #define SCNiLEAST8 "i"
165 #define SCNdFAST8 "d"
166 #define SCNiFAST8 "i"
170 #define SCNdLEAST16 "hd"
171 #define SCNiLEAST16 "hi"
172 #define SCNdFAST16 "hd"
173 #define SCNiFAST16 "hi"
177 #define SCNdLEAST32 "ld"
178 #define SCNiLEAST32 "li"
179 #define SCNdFAST32 "ld"
180 #define SCNiFAST32 "li"
182 #define SCNd64 "I64d"
183 #define SCNi64 "I64i"
184 #define SCNdLEAST64 "I64d"
185 #define SCNiLEAST64 "I64i"
186 #define SCNdFAST64 "I64d"
187 #define SCNiFAST64 "I64i"
189 #define SCNdMAX "I64d"
190 #define SCNiMAX "I64i"
193 # define SCNdPTR "I64d"
194 # define SCNiPTR "I64i"
196 # define SCNdPTR "ld"
197 # define SCNiPTR "li"
200 // The fscanf macros for unsigned integers are:
205 #define SCNoLEAST8 "o"
206 #define SCNuLEAST8 "u"
207 #define SCNxLEAST8 "x"
208 #define SCNXLEAST8 "X"
209 #define SCNoFAST8 "o"
210 #define SCNuFAST8 "u"
211 #define SCNxFAST8 "x"
212 #define SCNXFAST8 "X"
218 #define SCNoLEAST16 "ho"
219 #define SCNuLEAST16 "hu"
220 #define SCNxLEAST16 "hx"
221 #define SCNXLEAST16 "hX"
222 #define SCNoFAST16 "ho"
223 #define SCNuFAST16 "hu"
224 #define SCNxFAST16 "hx"
225 #define SCNXFAST16 "hX"
231 #define SCNoLEAST32 "lo"
232 #define SCNuLEAST32 "lu"
233 #define SCNxLEAST32 "lx"
234 #define SCNXLEAST32 "lX"
235 #define SCNoFAST32 "lo"
236 #define SCNuFAST32 "lu"
237 #define SCNxFAST32 "lx"
238 #define SCNXFAST32 "lX"
240 #define SCNo64 "I64o"
241 #define SCNu64 "I64u"
242 #define SCNx64 "I64x"
243 #define SCNX64 "I64X"
244 #define SCNoLEAST64 "I64o"
245 #define SCNuLEAST64 "I64u"
246 #define SCNxLEAST64 "I64x"
247 #define SCNXLEAST64 "I64X"
248 #define SCNoFAST64 "I64o"
249 #define SCNuFAST64 "I64u"
250 #define SCNxFAST64 "I64x"
251 #define SCNXFAST64 "I64X"
253 #define SCNoMAX "I64o"
254 #define SCNuMAX "I64u"
255 #define SCNxMAX "I64x"
256 #define SCNXMAX "I64X"
259 # define SCNoPTR "I64o"
260 # define SCNuPTR "I64u"
261 # define SCNxPTR "I64x"
262 # define SCNXPTR "I64X"
264 # define SCNoPTR "lo"
265 # define SCNuPTR "lu"
266 # define SCNxPTR "lx"
267 # define SCNXPTR "lX"
270 #endif // __STDC_FORMAT_MACROS ]
272 // 7.8.2 Functions for greatest-width integer types
274 // 7.8.2.1 The imaxabs function
275 #define imaxabs _abs64
277 // 7.8.2.2 The imaxdiv function
279 // This is modified version of div() function from Microsoft's div.c found
280 // in %MSVC.NET%\crt\src\div.c
281 #ifdef STATIC_IMAXDIV // [
283 #else // STATIC_IMAXDIV ][
285 #endif // STATIC_IMAXDIV ]
286 imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
290 result.quot = numer / denom;
291 result.rem = numer % denom;
293 if (numer < 0 && result.rem > 0) {
294 // did division wrong; must fix up
302 // 7.8.2.3 The strtoimax and strtoumax functions
303 #define strtoimax _strtoi64
304 #define strtoumax _strtoui64
306 // 7.8.2.4 The wcstoimax and wcstoumax functions
307 #define wcstoimax _wcstoi64
308 #define wcstoumax _wcstoui64
311 #endif // _MSC_INTTYPES_H_ ]