comparison inttypes.h @ 0:85c12d7e8144

Initial check in.
author alexander.chemeris@d525d15b-5824-0410-80a3-6185d19c2cde
date Mon, 11 Dec 2006 18:39:27 +0000
parents
children 0cf270b831ef
comparison
equal deleted inserted replaced
-1:000000000000 0:85c12d7e8144
1 // ISO C9x compliant inttypes.h for Miscrosoft Visual Studio
2 // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
3 //
4 // Copyright (c) 2006 Alexander Chemeris
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 ///////////////////////////////////////////////////////////////////////////////
20
21 // This file is only usable with Microsoft Visual Studio 2003 or later.
22 #ifdef _MSC_VER // [
23
24 #ifndef _MSC_INTTYPES_H_ // [
25 #define _MSC_INTTYPES_H_
26
27 #if _MSC_VER > 1000
28 #pragma once
29 #endif
30
31 #include <stdint.h>
32
33 // 7.8 Format conversion of integer types
34
35 typedef struct {
36 intmax_t quot;
37 intmax_t rem;
38 } imaxdiv_t;
39
40 // 7.8.1 Macros for format specifiers
41
42 // The fprintf macros for signed integers are:
43 #define PRId8 "d"
44 #define PRIi8 "i"
45 #define PRIdLEAST8 "d"
46 #define PRIiLEAST8 "i"
47 #define PRIdFAST8 "d"
48 #define PRIiFAST8 "i"
49
50 #define PRId16 "hd"
51 #define PRIi16 "hi"
52 #define PRIdLEAST16 "hd"
53 #define PRIiLEAST16 "hi"
54 #define PRIdFAST16 "hd"
55 #define PRIiFAST16 "hi"
56
57 #define PRId32 "I32d"
58 #define PRIi32 "I32i"
59 #define PRIdLEAST32 "I32d"
60 #define PRIiLEAST32 "I32i"
61 #define PRIdFAST32 "I32d"
62 #define PRIiFAST32 "I32i"
63
64 #define PRId64 "I64d"
65 #define PRIi64 "I64i"
66 #define PRIdLEAST64 "I64d"
67 #define PRIiLEAST64 "I64i"
68 #define PRIdFAST64 "I64d"
69 #define PRIiFAST64 "I64i"
70
71 #define PRIdMAX "I64d"
72 #define PRIiMAX "I64i"
73
74 #define PRIdPTR "Id"
75 #define PRIiPTR "Ii"
76
77 // The fprintf macros for unsigned integers are:
78 #define PRIo8 "o"
79 #define PRIu8 "u"
80 #define PRIx8 "x"
81 #define PRIX8 "X"
82 #define PRIoLEAST8 "o"
83 #define PRIuLEAST8 "u"
84 #define PRIxLEAST8 "x"
85 #define PRIXLEAST8 "X"
86 #define PRIoFAST8 "o"
87 #define PRIuFAST8 "u"
88 #define PRIxFAST8 "x"
89 #define PRIXFAST8 "X"
90
91 #define PRIo16 "ho"
92 #define PRIu16 "hu"
93 #define PRIx16 "hx"
94 #define PRIX16 "hX"
95 #define PRIoLEAST16 "ho"
96 #define PRIuLEAST16 "hu"
97 #define PRIxLEAST16 "hx"
98 #define PRIXLEAST16 "hX"
99 #define PRIoFAST16 "ho"
100 #define PRIuFAST16 "hu"
101 #define PRIxFAST16 "hx"
102 #define PRIXFAST16 "hX"
103
104 #define PRIo32 "I32o"
105 #define PRIu32 "I32u"
106 #define PRIx32 "I32x"
107 #define PRIX32 "I32X"
108 #define PRIoLEAST32 "I32o"
109 #define PRIuLEAST32 "I32u"
110 #define PRIxLEAST32 "I32x"
111 #define PRIXLEAST32 "I32X"
112 #define PRIoFAST32 "I32o"
113 #define PRIuFAST32 "I32u"
114 #define PRIxFAST32 "I32x"
115 #define PRIXFAST32 "I32X"
116
117 #define PRIo64 "I64o"
118 #define PRIu64 "I64u"
119 #define PRIx64 "I64x"
120 #define PRIX64 "I64X"
121 #define PRIoLEAST64 "I64o"
122 #define PRIuLEAST64 "I64u"
123 #define PRIxLEAST64 "I64x"
124 #define PRIXLEAST64 "I64X"
125 #define PRIoFAST64 "I64o"
126 #define PRIuFAST64 "I64u"
127 #define PRIxFAST64 "I64x"
128 #define PRIXFAST64 "I64X"
129
130 #define PRIoMAX "I64o"
131 #define PRIuMAX "I64u"
132 #define PRIxMAX "I64x"
133 #define PRIXMAX "I64X"
134
135 #define PRIoPTR "Io"
136 #define PRIuPTR "Iu"
137 #define PRIxPTR "Ix"
138 #define PRIXPTR "IX"
139
140 // The fscanf macros for signed integers are:
141 #define SCNd8 "d"
142 #define SCNi8 "i"
143 #define SCNdLEAST8 "d"
144 #define SCNiLEAST8 "i"
145 #define SCNdFAST8 "d"
146 #define SCNiFAST8 "i"
147
148 #define SCNd16 "hd"
149 #define SCNi16 "hi"
150 #define SCNdLEAST16 "hd"
151 #define SCNiLEAST16 "hi"
152 #define SCNdFAST16 "hd"
153 #define SCNiFAST16 "hi"
154
155 #define SCNd32 "ld"
156 #define SCNi32 "li"
157 #define SCNdLEAST32 "ld"
158 #define SCNiLEAST32 "li"
159 #define SCNdFAST32 "ld"
160 #define SCNiFAST32 "li"
161
162 #define SCNd64 "I64d"
163 #define SCNi64 "I64i"
164 #define SCNdLEAST64 "I64d"
165 #define SCNiLEAST64 "I64i"
166 #define SCNdFAST64 "I64d"
167 #define SCNiFAST64 "I64i"
168
169 #define SCNdMAX "I64d"
170 #define SCNiMAX "I64i"
171
172 #ifdef _WIN64 // [
173 # define SCNdPTR "I64d"
174 # define SCNiPTR "I64i"
175 #else // _WIN64 ][
176 # define SCNdPTR "ld"
177 # define SCNiPTR "li"
178 #endif // _WIN64 ]
179
180 // The fscanf macros for unsigned integers are:
181 #define SCNo8 "o"
182 #define SCNu8 "u"
183 #define SCNx8 "x"
184 #define SCNX8 "X"
185 #define SCNoLEAST8 "o"
186 #define SCNuLEAST8 "u"
187 #define SCNxLEAST8 "x"
188 #define SCNXLEAST8 "X"
189 #define SCNoFAST8 "o"
190 #define SCNuFAST8 "u"
191 #define SCNxFAST8 "x"
192 #define SCNXFAST8 "X"
193
194 #define SCNo16 "ho"
195 #define SCNu16 "hu"
196 #define SCNx16 "hx"
197 #define SCNX16 "hX"
198 #define SCNoLEAST16 "ho"
199 #define SCNuLEAST16 "hu"
200 #define SCNxLEAST16 "hx"
201 #define SCNXLEAST16 "hX"
202 #define SCNoFAST16 "ho"
203 #define SCNuFAST16 "hu"
204 #define SCNxFAST16 "hx"
205 #define SCNXFAST16 "hX"
206
207 #define SCNo32 "lo"
208 #define SCNu32 "lu"
209 #define SCNx32 "lx"
210 #define SCNX32 "lX"
211 #define SCNoLEAST32 "lo"
212 #define SCNuLEAST32 "lu"
213 #define SCNxLEAST32 "lx"
214 #define SCNXLEAST32 "lX"
215 #define SCNoFAST32 "lo"
216 #define SCNuFAST32 "lu"
217 #define SCNxFAST32 "lx"
218 #define SCNXFAST32 "lX"
219
220 #define SCNo64 "I64o"
221 #define SCNu64 "I64u"
222 #define SCNx64 "I64x"
223 #define SCNX64 "I64X"
224 #define SCNoLEAST64 "I64o"
225 #define SCNuLEAST64 "I64u"
226 #define SCNxLEAST64 "I64x"
227 #define SCNXLEAST64 "I64X"
228 #define SCNoFAST64 "I64o"
229 #define SCNuFAST64 "I64u"
230 #define SCNxFAST64 "I64x"
231 #define SCNXFAST64 "I64X"
232
233 #define SCNoMAX "I64o"
234 #define SCNuMAX "I64u"
235 #define SCNxMAX "I64x"
236 #define SCNXMAX "I64X"
237
238 #ifdef _WIN64 // [
239 # define SCNoPTR "I64o"
240 # define SCNuPTR "I64u"
241 # define SCNxPTR "I64x"
242 # define SCNXPTR "I64X"
243 #else // _WIN64 ][
244 # define SCNoPTR "lo"
245 # define SCNuPTR "lu"
246 # define SCNxPTR "lx"
247 # define SCNXPTR "lX"
248 #endif // _WIN64 ]
249
250 // 7.8.2 Functions for greatest-width integer types
251
252 // 7.8.2.1 The imaxabs function
253 #define imaxabs _abs64
254
255 // 7.8.2.2 The imaxdiv function
256
257 // This is modified version of div() function from Microsoft's div.c found
258 // in %MSVC.NET%\crt\src\div.c
259 _inline imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
260 {
261 imaxdiv_t result;
262
263 result.quot = numer / denom;
264 result.rem = numer % denom;
265
266 if (numer < 0 && result.rem > 0) {
267 // did division wrong; must fix up
268 ++result.quot;
269 result.rem -= denom;
270 }
271
272 return result;
273 }
274
275 // 7.8.2.3 The strtoimax and strtoumax functions
276 #define strtoimax _strtoi64
277 #define strtoumax _strtoui64
278
279 // 7.8.2.4 The wcstoimax and wcstoumax functions
280 #define wcstoimax _wcstoi64
281 #define wcstoumax _wcstoui64
282
283
284 #endif // _MSC_INTTYPES_H_ ]
285
286 #endif // _MSC_VER ]