Main MRPT website > C++ reference
MRPT logo

msvc_inttypes.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 // ISO C9x  compliant inttypes.h for Microsoft Visual Studio
00029 // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 
00030 // 
00031 //  Copyright (c) 2006 Alexander Chemeris
00032 // 
00033 // Redistribution and use in source and binary forms, with or without
00034 // modification, are permitted provided that the following conditions are met:
00035 // 
00036 //   1. Redistributions of source code must retain the above copyright notice,
00037 //      this list of conditions and the following disclaimer.
00038 // 
00039 //   2. Redistributions in binary form must reproduce the above copyright
00040 //      notice, this list of conditions and the following disclaimer in the
00041 //      documentation and/or other materials provided with the distribution.
00042 // 
00043 //   3. The name of the author may be used to endorse or promote products
00044 //      derived from this software without specific prior written permission.
00045 // 
00046 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00047 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00048 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00049 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00050 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00051 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00052 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00053 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00054 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00055 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00056 // 
00057 ///////////////////////////////////////////////////////////////////////////////
00058 
00059 #ifndef _MSC_VER // [
00060 #error "Use this header only with Microsoft Visual C++ compilers!"
00061 #endif // _MSC_VER ]
00062 
00063 #ifndef _MSC_INTTYPES_H_ // [
00064 #define _MSC_INTTYPES_H_
00065 
00066 #if _MSC_VER > 1000
00067 #pragma once
00068 #endif
00069 
00070 #include "pstdint.h"
00071 
00072 // 7.8 Format conversion of integer types
00073 
00074 typedef struct {
00075    intmax_t quot;
00076    intmax_t rem;
00077 } imaxdiv_t;
00078 
00079 // 7.8.1 Macros for format specifiers
00080 
00081 #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [   See footnote 185 at page 198
00082 
00083 // The fprintf macros for signed integers are:
00084 #define PRId8       "d"
00085 #define PRIi8       "i"
00086 #define PRIdLEAST8  "d"
00087 #define PRIiLEAST8  "i"
00088 #define PRIdFAST8   "d"
00089 #define PRIiFAST8   "i"
00090 
00091 #define PRId16       "hd"
00092 #define PRIi16       "hi"
00093 #define PRIdLEAST16  "hd"
00094 #define PRIiLEAST16  "hi"
00095 #define PRIdFAST16   "hd"
00096 #define PRIiFAST16   "hi"
00097 
00098 #define PRId32       "I32d"
00099 #define PRIi32       "I32i"
00100 #define PRIdLEAST32  "I32d"
00101 #define PRIiLEAST32  "I32i"
00102 #define PRIdFAST32   "I32d"
00103 #define PRIiFAST32   "I32i"
00104 
00105 #define PRId64       "I64d"
00106 #define PRIi64       "I64i"
00107 #define PRIdLEAST64  "I64d"
00108 #define PRIiLEAST64  "I64i"
00109 #define PRIdFAST64   "I64d"
00110 #define PRIiFAST64   "I64i"
00111 
00112 #define PRIdMAX     "I64d"
00113 #define PRIiMAX     "I64i"
00114 
00115 #define PRIdPTR     "Id"
00116 #define PRIiPTR     "Ii"
00117 
00118 // The fprintf macros for unsigned integers are:
00119 #define PRIo8       "o"
00120 #define PRIu8       "u"
00121 #define PRIx8       "x"
00122 #define PRIX8       "X"
00123 #define PRIoLEAST8  "o"
00124 #define PRIuLEAST8  "u"
00125 #define PRIxLEAST8  "x"
00126 #define PRIXLEAST8  "X"
00127 #define PRIoFAST8   "o"
00128 #define PRIuFAST8   "u"
00129 #define PRIxFAST8   "x"
00130 #define PRIXFAST8   "X"
00131 
00132 #define PRIo16       "ho"
00133 #define PRIu16       "hu"
00134 #define PRIx16       "hx"
00135 #define PRIX16       "hX"
00136 #define PRIoLEAST16  "ho"
00137 #define PRIuLEAST16  "hu"
00138 #define PRIxLEAST16  "hx"
00139 #define PRIXLEAST16  "hX"
00140 #define PRIoFAST16   "ho"
00141 #define PRIuFAST16   "hu"
00142 #define PRIxFAST16   "hx"
00143 #define PRIXFAST16   "hX"
00144 
00145 #define PRIo32       "I32o"
00146 #define PRIu32       "I32u"
00147 #define PRIx32       "I32x"
00148 #define PRIX32       "I32X"
00149 #define PRIoLEAST32  "I32o"
00150 #define PRIuLEAST32  "I32u"
00151 #define PRIxLEAST32  "I32x"
00152 #define PRIXLEAST32  "I32X"
00153 #define PRIoFAST32   "I32o"
00154 #define PRIuFAST32   "I32u"
00155 #define PRIxFAST32   "I32x"
00156 #define PRIXFAST32   "I32X"
00157 
00158 #define PRIo64       "I64o"
00159 #define PRIu64       "I64u"
00160 #define PRIx64       "I64x"
00161 #define PRIX64       "I64X"
00162 #define PRIoLEAST64  "I64o"
00163 #define PRIuLEAST64  "I64u"
00164 #define PRIxLEAST64  "I64x"
00165 #define PRIXLEAST64  "I64X"
00166 #define PRIoFAST64   "I64o"
00167 #define PRIuFAST64   "I64u"
00168 #define PRIxFAST64   "I64x"
00169 #define PRIXFAST64   "I64X"
00170 
00171 #define PRIoMAX     "I64o"
00172 #define PRIuMAX     "I64u"
00173 #define PRIxMAX     "I64x"
00174 #define PRIXMAX     "I64X"
00175 
00176 #define PRIoPTR     "Io"
00177 #define PRIuPTR     "Iu"
00178 #define PRIxPTR     "Ix"
00179 #define PRIXPTR     "IX"
00180 
00181 // The fscanf macros for signed integers are:
00182 #define SCNd8       "d"
00183 #define SCNi8       "i"
00184 #define SCNdLEAST8  "d"
00185 #define SCNiLEAST8  "i"
00186 #define SCNdFAST8   "d"
00187 #define SCNiFAST8   "i"
00188 
00189 #define SCNd16       "hd"
00190 #define SCNi16       "hi"
00191 #define SCNdLEAST16  "hd"
00192 #define SCNiLEAST16  "hi"
00193 #define SCNdFAST16   "hd"
00194 #define SCNiFAST16   "hi"
00195 
00196 #define SCNd32       "ld"
00197 #define SCNi32       "li"
00198 #define SCNdLEAST32  "ld"
00199 #define SCNiLEAST32  "li"
00200 #define SCNdFAST32   "ld"
00201 #define SCNiFAST32   "li"
00202 
00203 #define SCNd64       "I64d"
00204 #define SCNi64       "I64i"
00205 #define SCNdLEAST64  "I64d"
00206 #define SCNiLEAST64  "I64i"
00207 #define SCNdFAST64   "I64d"
00208 #define SCNiFAST64   "I64i"
00209 
00210 #define SCNdMAX     "I64d"
00211 #define SCNiMAX     "I64i"
00212 
00213 #ifdef _WIN64 // [
00214 #  define SCNdPTR     "I64d"
00215 #  define SCNiPTR     "I64i"
00216 #else  // _WIN64 ][
00217 #  define SCNdPTR     "ld"
00218 #  define SCNiPTR     "li"
00219 #endif  // _WIN64 ]
00220 
00221 // The fscanf macros for unsigned integers are:
00222 #define SCNo8       "o"
00223 #define SCNu8       "u"
00224 #define SCNx8       "x"
00225 #define SCNX8       "X"
00226 #define SCNoLEAST8  "o"
00227 #define SCNuLEAST8  "u"
00228 #define SCNxLEAST8  "x"
00229 #define SCNXLEAST8  "X"
00230 #define SCNoFAST8   "o"
00231 #define SCNuFAST8   "u"
00232 #define SCNxFAST8   "x"
00233 #define SCNXFAST8   "X"
00234 
00235 #define SCNo16       "ho"
00236 #define SCNu16       "hu"
00237 #define SCNx16       "hx"
00238 #define SCNX16       "hX"
00239 #define SCNoLEAST16  "ho"
00240 #define SCNuLEAST16  "hu"
00241 #define SCNxLEAST16  "hx"
00242 #define SCNXLEAST16  "hX"
00243 #define SCNoFAST16   "ho"
00244 #define SCNuFAST16   "hu"
00245 #define SCNxFAST16   "hx"
00246 #define SCNXFAST16   "hX"
00247 
00248 #define SCNo32       "lo"
00249 #define SCNu32       "lu"
00250 #define SCNx32       "lx"
00251 #define SCNX32       "lX"
00252 #define SCNoLEAST32  "lo"
00253 #define SCNuLEAST32  "lu"
00254 #define SCNxLEAST32  "lx"
00255 #define SCNXLEAST32  "lX"
00256 #define SCNoFAST32   "lo"
00257 #define SCNuFAST32   "lu"
00258 #define SCNxFAST32   "lx"
00259 #define SCNXFAST32   "lX"
00260 
00261 #define SCNo64       "I64o"
00262 #define SCNu64       "I64u"
00263 #define SCNx64       "I64x"
00264 #define SCNX64       "I64X"
00265 #define SCNoLEAST64  "I64o"
00266 #define SCNuLEAST64  "I64u"
00267 #define SCNxLEAST64  "I64x"
00268 #define SCNXLEAST64  "I64X"
00269 #define SCNoFAST64   "I64o"
00270 #define SCNuFAST64   "I64u"
00271 #define SCNxFAST64   "I64x"
00272 #define SCNXFAST64   "I64X"
00273 
00274 #define SCNoMAX     "I64o"
00275 #define SCNuMAX     "I64u"
00276 #define SCNxMAX     "I64x"
00277 #define SCNXMAX     "I64X"
00278 
00279 #ifdef _WIN64 // [
00280 #  define SCNoPTR     "I64o"
00281 #  define SCNuPTR     "I64u"
00282 #  define SCNxPTR     "I64x"
00283 #  define SCNXPTR     "I64X"
00284 #else  // _WIN64 ][
00285 #  define SCNoPTR     "lo"
00286 #  define SCNuPTR     "lu"
00287 #  define SCNxPTR     "lx"
00288 #  define SCNXPTR     "lX"
00289 #endif  // _WIN64 ]
00290 
00291 #endif // __STDC_FORMAT_MACROS ]
00292 
00293 // 7.8.2 Functions for greatest-width integer types
00294 
00295 // 7.8.2.1 The imaxabs function
00296 #define imaxabs _abs64
00297 
00298 // 7.8.2.2 The imaxdiv function
00299 
00300 // This is modified version of div() function from Microsoft's div.c found
00301 // in %MSVC.NET%\crt\src\div.c
00302 #ifdef STATIC_IMAXDIV // [
00303 static
00304 #else // STATIC_IMAXDIV ][
00305 _inline
00306 #endif // STATIC_IMAXDIV ]
00307 imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
00308 {
00309    imaxdiv_t result;
00310 
00311    result.quot = numer / denom;
00312    result.rem = numer % denom;
00313 
00314    if (numer < 0 && result.rem > 0) {
00315       // did division wrong; must fix up
00316       ++result.quot;
00317       result.rem -= denom;
00318    }
00319 
00320    return result;
00321 }
00322 
00323 // 7.8.2.3 The strtoimax and strtoumax functions
00324 #define strtoimax _strtoi64
00325 #define strtoumax _strtoui64
00326 
00327 // 7.8.2.4 The wcstoimax and wcstoumax functions
00328 #define wcstoimax _wcstoi64
00329 #define wcstoumax _wcstoui64
00330 
00331 
00332 #endif // _MSC_INTTYPES_H_ ]



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011