Open Broadcaster Software
Free, open source software for live streaming and recording
vc_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 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. The name of the author may be used to endorse or promote products
17 // derived from this software without specific prior written permission.
18 //
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.
29 //
31 
32 #ifndef _MSC_VER // [
33 #error "Use this header only with Microsoft Visual C++ compilers!"
34 #endif // _MSC_VER ]
35 
36 #ifndef _MSC_INTTYPES_H_ // [
37 #define _MSC_INTTYPES_H_
38 
39 #if _MSC_VER > 1000
40 #pragma once
41 #endif
42 
43 #include "stdint.h"
44 
45 // 7.8 Format conversion of integer types
46 
47 typedef struct {
50 } imaxdiv_t;
51 
52 // 7.8.1 Macros for format specifiers
53 
54 #if !defined(__cplusplus) || \
55  defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
56 
57 // The fprintf macros for signed integers are:
58 #define PRId8 "d"
59 #define PRIi8 "i"
60 #define PRIdLEAST8 "d"
61 #define PRIiLEAST8 "i"
62 #define PRIdFAST8 "d"
63 #define PRIiFAST8 "i"
64 
65 #define PRId16 "hd"
66 #define PRIi16 "hi"
67 #define PRIdLEAST16 "hd"
68 #define PRIiLEAST16 "hi"
69 #define PRIdFAST16 "hd"
70 #define PRIiFAST16 "hi"
71 
72 #define PRId32 "I32d"
73 #define PRIi32 "I32i"
74 #define PRIdLEAST32 "I32d"
75 #define PRIiLEAST32 "I32i"
76 #define PRIdFAST32 "I32d"
77 #define PRIiFAST32 "I32i"
78 
79 #define PRId64 "I64d"
80 #define PRIi64 "I64i"
81 #define PRIdLEAST64 "I64d"
82 #define PRIiLEAST64 "I64i"
83 #define PRIdFAST64 "I64d"
84 #define PRIiFAST64 "I64i"
85 
86 #define PRIdMAX "I64d"
87 #define PRIiMAX "I64i"
88 
89 #define PRIdPTR "Id"
90 #define PRIiPTR "Ii"
91 
92 // The fprintf macros for unsigned integers are:
93 #define PRIo8 "o"
94 #define PRIu8 "u"
95 #define PRIx8 "x"
96 #define PRIX8 "X"
97 #define PRIoLEAST8 "o"
98 #define PRIuLEAST8 "u"
99 #define PRIxLEAST8 "x"
100 #define PRIXLEAST8 "X"
101 #define PRIoFAST8 "o"
102 #define PRIuFAST8 "u"
103 #define PRIxFAST8 "x"
104 #define PRIXFAST8 "X"
105 
106 #define PRIo16 "ho"
107 #define PRIu16 "hu"
108 #define PRIx16 "hx"
109 #define PRIX16 "hX"
110 #define PRIoLEAST16 "ho"
111 #define PRIuLEAST16 "hu"
112 #define PRIxLEAST16 "hx"
113 #define PRIXLEAST16 "hX"
114 #define PRIoFAST16 "ho"
115 #define PRIuFAST16 "hu"
116 #define PRIxFAST16 "hx"
117 #define PRIXFAST16 "hX"
118 
119 #define PRIo32 "I32o"
120 #define PRIu32 "I32u"
121 #define PRIx32 "I32x"
122 #define PRIX32 "I32X"
123 #define PRIoLEAST32 "I32o"
124 #define PRIuLEAST32 "I32u"
125 #define PRIxLEAST32 "I32x"
126 #define PRIXLEAST32 "I32X"
127 #define PRIoFAST32 "I32o"
128 #define PRIuFAST32 "I32u"
129 #define PRIxFAST32 "I32x"
130 #define PRIXFAST32 "I32X"
131 
132 #define PRIo64 "I64o"
133 #define PRIu64 "I64u"
134 #define PRIx64 "I64x"
135 #define PRIX64 "I64X"
136 #define PRIoLEAST64 "I64o"
137 #define PRIuLEAST64 "I64u"
138 #define PRIxLEAST64 "I64x"
139 #define PRIXLEAST64 "I64X"
140 #define PRIoFAST64 "I64o"
141 #define PRIuFAST64 "I64u"
142 #define PRIxFAST64 "I64x"
143 #define PRIXFAST64 "I64X"
144 
145 #define PRIoMAX "I64o"
146 #define PRIuMAX "I64u"
147 #define PRIxMAX "I64x"
148 #define PRIXMAX "I64X"
149 
150 #define PRIoPTR "Io"
151 #define PRIuPTR "Iu"
152 #define PRIxPTR "Ix"
153 #define PRIXPTR "IX"
154 
155 // The fscanf macros for signed integers are:
156 #define SCNd16 "hd"
157 #define SCNi16 "hi"
158 #define SCNdLEAST16 "hd"
159 #define SCNiLEAST16 "hi"
160 #define SCNdFAST16 "hd"
161 #define SCNiFAST16 "hi"
162 
163 #define SCNd32 "ld"
164 #define SCNi32 "li"
165 #define SCNdLEAST32 "ld"
166 #define SCNiLEAST32 "li"
167 #define SCNdFAST32 "ld"
168 #define SCNiFAST32 "li"
169 
170 #define SCNd64 "I64d"
171 #define SCNi64 "I64i"
172 #define SCNdLEAST64 "I64d"
173 #define SCNiLEAST64 "I64i"
174 #define SCNdFAST64 "I64d"
175 #define SCNiFAST64 "I64i"
176 
177 #define SCNdMAX "I64d"
178 #define SCNiMAX "I64i"
179 
180 #ifdef _WIN64 // [
181 #define SCNdPTR "I64d"
182 #define SCNiPTR "I64i"
183 #else // _WIN64 ][
184 #define SCNdPTR "ld"
185 #define SCNiPTR "li"
186 #endif // _WIN64 ]
187 
188 // The fscanf macros for unsigned integers are:
189 #define SCNo16 "ho"
190 #define SCNu16 "hu"
191 #define SCNx16 "hx"
192 #define SCNX16 "hX"
193 #define SCNoLEAST16 "ho"
194 #define SCNuLEAST16 "hu"
195 #define SCNxLEAST16 "hx"
196 #define SCNXLEAST16 "hX"
197 #define SCNoFAST16 "ho"
198 #define SCNuFAST16 "hu"
199 #define SCNxFAST16 "hx"
200 #define SCNXFAST16 "hX"
201 
202 #define SCNo32 "lo"
203 #define SCNu32 "lu"
204 #define SCNx32 "lx"
205 #define SCNX32 "lX"
206 #define SCNoLEAST32 "lo"
207 #define SCNuLEAST32 "lu"
208 #define SCNxLEAST32 "lx"
209 #define SCNXLEAST32 "lX"
210 #define SCNoFAST32 "lo"
211 #define SCNuFAST32 "lu"
212 #define SCNxFAST32 "lx"
213 #define SCNXFAST32 "lX"
214 
215 #define SCNo64 "I64o"
216 #define SCNu64 "I64u"
217 #define SCNx64 "I64x"
218 #define SCNX64 "I64X"
219 #define SCNoLEAST64 "I64o"
220 #define SCNuLEAST64 "I64u"
221 #define SCNxLEAST64 "I64x"
222 #define SCNXLEAST64 "I64X"
223 #define SCNoFAST64 "I64o"
224 #define SCNuFAST64 "I64u"
225 #define SCNxFAST64 "I64x"
226 #define SCNXFAST64 "I64X"
227 
228 #define SCNoMAX "I64o"
229 #define SCNuMAX "I64u"
230 #define SCNxMAX "I64x"
231 #define SCNXMAX "I64X"
232 
233 #ifdef _WIN64 // [
234 #define SCNoPTR "I64o"
235 #define SCNuPTR "I64u"
236 #define SCNxPTR "I64x"
237 #define SCNXPTR "I64X"
238 #else // _WIN64 ][
239 #define SCNoPTR "lo"
240 #define SCNuPTR "lu"
241 #define SCNxPTR "lx"
242 #define SCNXPTR "lX"
243 #endif // _WIN64 ]
244 
245 #endif // __STDC_FORMAT_MACROS ]
246 
247 // 7.8.2 Functions for greatest-width integer types
248 
249 // 7.8.2.1 The imaxabs function
250 #define imaxabs _abs64
251 
252 // 7.8.2.2 The imaxdiv function
253 
254 // This is modified version of div() function from Microsoft's div.c found
255 // in %MSVC.NET%\crt\src\div.c
256 #ifdef STATIC_IMAXDIV // [
257 static
258 #else // STATIC_IMAXDIV ][
259 _inline
260 #endif // STATIC_IMAXDIV ]
261  imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
262 {
263  imaxdiv_t result;
264 
265  result.quot = numer / denom;
266  result.rem = numer % denom;
267 
268  if (numer < 0 && result.rem > 0) {
269  // did division wrong; must fix up
270  ++result.quot;
271  result.rem -= denom;
272  }
273 
274  return result;
275 }
276 
277 // 7.8.2.3 The strtoimax and strtoumax functions
278 #define strtoimax _strtoi64
279 #define strtoumax _strtoui64
280 
281 // 7.8.2.4 The wcstoimax and wcstoumax functions
282 #define wcstoimax _wcstoi64
283 #define wcstoumax _wcstoui64
284 
285 #endif // _MSC_INTTYPES_H_ ]
Definition: vc_inttypes.h:47
_inline imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
Definition: vc_inttypes.h:261
__int64 intmax_t
Definition: vc_stdint.h:63
intmax_t rem
Definition: vc_inttypes.h:49
intmax_t quot
Definition: vc_inttypes.h:48