msc/inttypes.h

changeset 102
7c8ebad4d973
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/msc/inttypes.h	Thu Feb 28 08:17:26 2013 +0100
     1.3 @@ -0,0 +1,305 @@
     1.4 +// ISO C9x  compliant inttypes.h for Microsoft Visual Studio
     1.5 +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 
     1.6 +// 
     1.7 +//  Copyright (c) 2006 Alexander Chemeris
     1.8 +// 
     1.9 +// Redistribution and use in source and binary forms, with or without
    1.10 +// modification, are permitted provided that the following conditions are met:
    1.11 +// 
    1.12 +//   1. Redistributions of source code must retain the above copyright notice,
    1.13 +//      this list of conditions and the following disclaimer.
    1.14 +// 
    1.15 +//   2. Redistributions in binary form must reproduce the above copyright
    1.16 +//      notice, this list of conditions and the following disclaimer in the
    1.17 +//      documentation and/or other materials provided with the distribution.
    1.18 +// 
    1.19 +//   3. The name of the author may be used to endorse or promote products
    1.20 +//      derived from this software without specific prior written permission.
    1.21 +// 
    1.22 +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
    1.23 +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    1.24 +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
    1.25 +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.27 +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    1.28 +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
    1.29 +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    1.30 +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    1.31 +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +// 
    1.33 +///////////////////////////////////////////////////////////////////////////////
    1.34 +
    1.35 +#ifndef _MSC_VER // [
    1.36 +#error "Use this header only with Microsoft Visual C++ compilers!"
    1.37 +#endif // _MSC_VER ]
    1.38 +
    1.39 +#ifndef _MSC_INTTYPES_H_ // [
    1.40 +#define _MSC_INTTYPES_H_
    1.41 +
    1.42 +#if _MSC_VER > 1000
    1.43 +#pragma once
    1.44 +#endif
    1.45 +
    1.46 +#include "stdint.h"
    1.47 +
    1.48 +// 7.8 Format conversion of integer types
    1.49 +
    1.50 +typedef struct {
    1.51 +   intmax_t quot;
    1.52 +   intmax_t rem;
    1.53 +} imaxdiv_t;
    1.54 +
    1.55 +// 7.8.1 Macros for format specifiers
    1.56 +
    1.57 +#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [   See footnote 185 at page 198
    1.58 +
    1.59 +// The fprintf macros for signed integers are:
    1.60 +#define PRId8       "d"
    1.61 +#define PRIi8       "i"
    1.62 +#define PRIdLEAST8  "d"
    1.63 +#define PRIiLEAST8  "i"
    1.64 +#define PRIdFAST8   "d"
    1.65 +#define PRIiFAST8   "i"
    1.66 +
    1.67 +#define PRId16       "hd"
    1.68 +#define PRIi16       "hi"
    1.69 +#define PRIdLEAST16  "hd"
    1.70 +#define PRIiLEAST16  "hi"
    1.71 +#define PRIdFAST16   "hd"
    1.72 +#define PRIiFAST16   "hi"
    1.73 +
    1.74 +#define PRId32       "I32d"
    1.75 +#define PRIi32       "I32i"
    1.76 +#define PRIdLEAST32  "I32d"
    1.77 +#define PRIiLEAST32  "I32i"
    1.78 +#define PRIdFAST32   "I32d"
    1.79 +#define PRIiFAST32   "I32i"
    1.80 +
    1.81 +#define PRId64       "I64d"
    1.82 +#define PRIi64       "I64i"
    1.83 +#define PRIdLEAST64  "I64d"
    1.84 +#define PRIiLEAST64  "I64i"
    1.85 +#define PRIdFAST64   "I64d"
    1.86 +#define PRIiFAST64   "I64i"
    1.87 +
    1.88 +#define PRIdMAX     "I64d"
    1.89 +#define PRIiMAX     "I64i"
    1.90 +
    1.91 +#define PRIdPTR     "Id"
    1.92 +#define PRIiPTR     "Ii"
    1.93 +
    1.94 +// The fprintf macros for unsigned integers are:
    1.95 +#define PRIo8       "o"
    1.96 +#define PRIu8       "u"
    1.97 +#define PRIx8       "x"
    1.98 +#define PRIX8       "X"
    1.99 +#define PRIoLEAST8  "o"
   1.100 +#define PRIuLEAST8  "u"
   1.101 +#define PRIxLEAST8  "x"
   1.102 +#define PRIXLEAST8  "X"
   1.103 +#define PRIoFAST8   "o"
   1.104 +#define PRIuFAST8   "u"
   1.105 +#define PRIxFAST8   "x"
   1.106 +#define PRIXFAST8   "X"
   1.107 +
   1.108 +#define PRIo16       "ho"
   1.109 +#define PRIu16       "hu"
   1.110 +#define PRIx16       "hx"
   1.111 +#define PRIX16       "hX"
   1.112 +#define PRIoLEAST16  "ho"
   1.113 +#define PRIuLEAST16  "hu"
   1.114 +#define PRIxLEAST16  "hx"
   1.115 +#define PRIXLEAST16  "hX"
   1.116 +#define PRIoFAST16   "ho"
   1.117 +#define PRIuFAST16   "hu"
   1.118 +#define PRIxFAST16   "hx"
   1.119 +#define PRIXFAST16   "hX"
   1.120 +
   1.121 +#define PRIo32       "I32o"
   1.122 +#define PRIu32       "I32u"
   1.123 +#define PRIx32       "I32x"
   1.124 +#define PRIX32       "I32X"
   1.125 +#define PRIoLEAST32  "I32o"
   1.126 +#define PRIuLEAST32  "I32u"
   1.127 +#define PRIxLEAST32  "I32x"
   1.128 +#define PRIXLEAST32  "I32X"
   1.129 +#define PRIoFAST32   "I32o"
   1.130 +#define PRIuFAST32   "I32u"
   1.131 +#define PRIxFAST32   "I32x"
   1.132 +#define PRIXFAST32   "I32X"
   1.133 +
   1.134 +#define PRIo64       "I64o"
   1.135 +#define PRIu64       "I64u"
   1.136 +#define PRIx64       "I64x"
   1.137 +#define PRIX64       "I64X"
   1.138 +#define PRIoLEAST64  "I64o"
   1.139 +#define PRIuLEAST64  "I64u"
   1.140 +#define PRIxLEAST64  "I64x"
   1.141 +#define PRIXLEAST64  "I64X"
   1.142 +#define PRIoFAST64   "I64o"
   1.143 +#define PRIuFAST64   "I64u"
   1.144 +#define PRIxFAST64   "I64x"
   1.145 +#define PRIXFAST64   "I64X"
   1.146 +
   1.147 +#define PRIoMAX     "I64o"
   1.148 +#define PRIuMAX     "I64u"
   1.149 +#define PRIxMAX     "I64x"
   1.150 +#define PRIXMAX     "I64X"
   1.151 +
   1.152 +#define PRIoPTR     "Io"
   1.153 +#define PRIuPTR     "Iu"
   1.154 +#define PRIxPTR     "Ix"
   1.155 +#define PRIXPTR     "IX"
   1.156 +
   1.157 +// The fscanf macros for signed integers are:
   1.158 +#define SCNd8       "d"
   1.159 +#define SCNi8       "i"
   1.160 +#define SCNdLEAST8  "d"
   1.161 +#define SCNiLEAST8  "i"
   1.162 +#define SCNdFAST8   "d"
   1.163 +#define SCNiFAST8   "i"
   1.164 +
   1.165 +#define SCNd16       "hd"
   1.166 +#define SCNi16       "hi"
   1.167 +#define SCNdLEAST16  "hd"
   1.168 +#define SCNiLEAST16  "hi"
   1.169 +#define SCNdFAST16   "hd"
   1.170 +#define SCNiFAST16   "hi"
   1.171 +
   1.172 +#define SCNd32       "ld"
   1.173 +#define SCNi32       "li"
   1.174 +#define SCNdLEAST32  "ld"
   1.175 +#define SCNiLEAST32  "li"
   1.176 +#define SCNdFAST32   "ld"
   1.177 +#define SCNiFAST32   "li"
   1.178 +
   1.179 +#define SCNd64       "I64d"
   1.180 +#define SCNi64       "I64i"
   1.181 +#define SCNdLEAST64  "I64d"
   1.182 +#define SCNiLEAST64  "I64i"
   1.183 +#define SCNdFAST64   "I64d"
   1.184 +#define SCNiFAST64   "I64i"
   1.185 +
   1.186 +#define SCNdMAX     "I64d"
   1.187 +#define SCNiMAX     "I64i"
   1.188 +
   1.189 +#ifdef _WIN64 // [
   1.190 +#  define SCNdPTR     "I64d"
   1.191 +#  define SCNiPTR     "I64i"
   1.192 +#else  // _WIN64 ][
   1.193 +#  define SCNdPTR     "ld"
   1.194 +#  define SCNiPTR     "li"
   1.195 +#endif  // _WIN64 ]
   1.196 +
   1.197 +// The fscanf macros for unsigned integers are:
   1.198 +#define SCNo8       "o"
   1.199 +#define SCNu8       "u"
   1.200 +#define SCNx8       "x"
   1.201 +#define SCNX8       "X"
   1.202 +#define SCNoLEAST8  "o"
   1.203 +#define SCNuLEAST8  "u"
   1.204 +#define SCNxLEAST8  "x"
   1.205 +#define SCNXLEAST8  "X"
   1.206 +#define SCNoFAST8   "o"
   1.207 +#define SCNuFAST8   "u"
   1.208 +#define SCNxFAST8   "x"
   1.209 +#define SCNXFAST8   "X"
   1.210 +
   1.211 +#define SCNo16       "ho"
   1.212 +#define SCNu16       "hu"
   1.213 +#define SCNx16       "hx"
   1.214 +#define SCNX16       "hX"
   1.215 +#define SCNoLEAST16  "ho"
   1.216 +#define SCNuLEAST16  "hu"
   1.217 +#define SCNxLEAST16  "hx"
   1.218 +#define SCNXLEAST16  "hX"
   1.219 +#define SCNoFAST16   "ho"
   1.220 +#define SCNuFAST16   "hu"
   1.221 +#define SCNxFAST16   "hx"
   1.222 +#define SCNXFAST16   "hX"
   1.223 +
   1.224 +#define SCNo32       "lo"
   1.225 +#define SCNu32       "lu"
   1.226 +#define SCNx32       "lx"
   1.227 +#define SCNX32       "lX"
   1.228 +#define SCNoLEAST32  "lo"
   1.229 +#define SCNuLEAST32  "lu"
   1.230 +#define SCNxLEAST32  "lx"
   1.231 +#define SCNXLEAST32  "lX"
   1.232 +#define SCNoFAST32   "lo"
   1.233 +#define SCNuFAST32   "lu"
   1.234 +#define SCNxFAST32   "lx"
   1.235 +#define SCNXFAST32   "lX"
   1.236 +
   1.237 +#define SCNo64       "I64o"
   1.238 +#define SCNu64       "I64u"
   1.239 +#define SCNx64       "I64x"
   1.240 +#define SCNX64       "I64X"
   1.241 +#define SCNoLEAST64  "I64o"
   1.242 +#define SCNuLEAST64  "I64u"
   1.243 +#define SCNxLEAST64  "I64x"
   1.244 +#define SCNXLEAST64  "I64X"
   1.245 +#define SCNoFAST64   "I64o"
   1.246 +#define SCNuFAST64   "I64u"
   1.247 +#define SCNxFAST64   "I64x"
   1.248 +#define SCNXFAST64   "I64X"
   1.249 +
   1.250 +#define SCNoMAX     "I64o"
   1.251 +#define SCNuMAX     "I64u"
   1.252 +#define SCNxMAX     "I64x"
   1.253 +#define SCNXMAX     "I64X"
   1.254 +
   1.255 +#ifdef _WIN64 // [
   1.256 +#  define SCNoPTR     "I64o"
   1.257 +#  define SCNuPTR     "I64u"
   1.258 +#  define SCNxPTR     "I64x"
   1.259 +#  define SCNXPTR     "I64X"
   1.260 +#else  // _WIN64 ][
   1.261 +#  define SCNoPTR     "lo"
   1.262 +#  define SCNuPTR     "lu"
   1.263 +#  define SCNxPTR     "lx"
   1.264 +#  define SCNXPTR     "lX"
   1.265 +#endif  // _WIN64 ]
   1.266 +
   1.267 +#endif // __STDC_FORMAT_MACROS ]
   1.268 +
   1.269 +// 7.8.2 Functions for greatest-width integer types
   1.270 +
   1.271 +// 7.8.2.1 The imaxabs function
   1.272 +#define imaxabs _abs64
   1.273 +
   1.274 +// 7.8.2.2 The imaxdiv function
   1.275 +
   1.276 +// This is modified version of div() function from Microsoft's div.c found
   1.277 +// in %MSVC.NET%\crt\src\div.c
   1.278 +#ifdef STATIC_IMAXDIV // [
   1.279 +static
   1.280 +#else // STATIC_IMAXDIV ][
   1.281 +_inline
   1.282 +#endif // STATIC_IMAXDIV ]
   1.283 +imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
   1.284 +{
   1.285 +   imaxdiv_t result;
   1.286 +
   1.287 +   result.quot = numer / denom;
   1.288 +   result.rem = numer % denom;
   1.289 +
   1.290 +   if (numer < 0 && result.rem > 0) {
   1.291 +      // did division wrong; must fix up
   1.292 +      ++result.quot;
   1.293 +      result.rem -= denom;
   1.294 +   }
   1.295 +
   1.296 +   return result;
   1.297 +}
   1.298 +
   1.299 +// 7.8.2.3 The strtoimax and strtoumax functions
   1.300 +#define strtoimax _strtoi64
   1.301 +#define strtoumax _strtoui64
   1.302 +
   1.303 +// 7.8.2.4 The wcstoimax and wcstoumax functions
   1.304 +#define wcstoimax _wcstoi64
   1.305 +#define wcstoumax _wcstoui64
   1.306 +
   1.307 +
   1.308 +#endif // _MSC_INTTYPES_H_ ]

mercurial