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



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019