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