Back to home page

Enduro/X

 
 

    


0001 // ISO C9x  compliant inttypes.h for Microsoft Visual Studio
0002 // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
0003 //
0004 //  Copyright (c) 2006 Alexander Chemeris
0005 //
0006 // Redistribution and use in source and binary forms, with or without
0007 // modification, are permitted provided that the following conditions are met:
0008 //
0009 //   1. Redistributions of source code must retain the above copyright notice,
0010 //      this list of conditions and the following disclaimer.
0011 //
0012 //   2. Redistributions in binary form must reproduce the above copyright
0013 //      notice, this list of conditions and the following disclaimer in the
0014 //      documentation and/or other materials provided with the distribution.
0015 //
0016 //   3. The name of the author may be used to endorse or promote products
0017 //      derived from this software without specific prior written permission.
0018 //
0019 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
0020 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
0021 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
0022 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
0025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
0026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
0027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
0028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029 //
0030 ///////////////////////////////////////////////////////////////////////////////
0031 
0032 #ifndef _MSC_VER // [
0033 #error "Use this header only with Microsoft Visual C++ compilers!"
0034 #else // _MSC_VER ]
0035 
0036 #ifndef _MSC_INTTYPES_H_ // [
0037 #define _MSC_INTTYPES_H_
0038 
0039 #if _MSC_VER > 1000
0040 #pragma once
0041 #endif
0042 
0043 #include "stdint.h"
0044 
0045 // 7.8 Format conversion of integer types
0046 
0047 typedef struct {
0048    intmax_t quot;
0049    intmax_t rem;
0050 } imaxdiv_t;
0051 
0052 // 7.8.1 Macros for format specifiers
0053 
0054 #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [   See footnote 185 at page 198
0055 
0056 // The fprintf macros for signed integers are:
0057 #define PRId8       "d"
0058 #define PRIi8       "i"
0059 #define PRIdLEAST8  "d"
0060 #define PRIiLEAST8  "i"
0061 #define PRIdFAST8   "d"
0062 #define PRIiFAST8   "i"
0063 
0064 #define PRId16       "hd"
0065 #define PRIi16       "hi"
0066 #define PRIdLEAST16  "hd"
0067 #define PRIiLEAST16  "hi"
0068 #define PRIdFAST16   "hd"
0069 #define PRIiFAST16   "hi"
0070 
0071 #define PRId32       "I32d"
0072 #define PRIi32       "I32i"
0073 #define PRIdLEAST32  "I32d"
0074 #define PRIiLEAST32  "I32i"
0075 #define PRIdFAST32   "I32d"
0076 #define PRIiFAST32   "I32i"
0077 
0078 #define PRId64       "I64d"
0079 #define PRIi64       "I64i"
0080 #define PRIdLEAST64  "I64d"
0081 #define PRIiLEAST64  "I64i"
0082 #define PRIdFAST64   "I64d"
0083 #define PRIiFAST64   "I64i"
0084 
0085 #define PRIdMAX     "I64d"
0086 #define PRIiMAX     "I64i"
0087 
0088 #define PRIdPTR     "Id"
0089 #define PRIiPTR     "Ii"
0090 
0091 // The fprintf macros for unsigned integers are:
0092 #define PRIo8       "o"
0093 #define PRIu8       "u"
0094 #define PRIx8       "x"
0095 #define PRIX8       "X"
0096 #define PRIoLEAST8  "o"
0097 #define PRIuLEAST8  "u"
0098 #define PRIxLEAST8  "x"
0099 #define PRIXLEAST8  "X"
0100 #define PRIoFAST8   "o"
0101 #define PRIuFAST8   "u"
0102 #define PRIxFAST8   "x"
0103 #define PRIXFAST8   "X"
0104 
0105 #define PRIo16       "ho"
0106 #define PRIu16       "hu"
0107 #define PRIx16       "hx"
0108 #define PRIX16       "hX"
0109 #define PRIoLEAST16  "ho"
0110 #define PRIuLEAST16  "hu"
0111 #define PRIxLEAST16  "hx"
0112 #define PRIXLEAST16  "hX"
0113 #define PRIoFAST16   "ho"
0114 #define PRIuFAST16   "hu"
0115 #define PRIxFAST16   "hx"
0116 #define PRIXFAST16   "hX"
0117 
0118 #define PRIo32       "I32o"
0119 #define PRIu32       "I32u"
0120 #define PRIx32       "I32x"
0121 #define PRIX32       "I32X"
0122 #define PRIoLEAST32  "I32o"
0123 #define PRIuLEAST32  "I32u"
0124 #define PRIxLEAST32  "I32x"
0125 #define PRIXLEAST32  "I32X"
0126 #define PRIoFAST32   "I32o"
0127 #define PRIuFAST32   "I32u"
0128 #define PRIxFAST32   "I32x"
0129 #define PRIXFAST32   "I32X"
0130 
0131 #define PRIo64       "I64o"
0132 #define PRIu64       "I64u"
0133 #define PRIx64       "I64x"
0134 #define PRIX64       "I64X"
0135 #define PRIoLEAST64  "I64o"
0136 #define PRIuLEAST64  "I64u"
0137 #define PRIxLEAST64  "I64x"
0138 #define PRIXLEAST64  "I64X"
0139 #define PRIoFAST64   "I64o"
0140 #define PRIuFAST64   "I64u"
0141 #define PRIxFAST64   "I64x"
0142 #define PRIXFAST64   "I64X"
0143 
0144 #define PRIoMAX     "I64o"
0145 #define PRIuMAX     "I64u"
0146 #define PRIxMAX     "I64x"
0147 #define PRIXMAX     "I64X"
0148 
0149 #define PRIoPTR     "Io"
0150 #define PRIuPTR     "Iu"
0151 #define PRIxPTR     "Ix"
0152 #define PRIXPTR     "IX"
0153 
0154 // The fscanf macros for signed integers are:
0155 #define SCNd8       "d"
0156 #define SCNi8       "i"
0157 #define SCNdLEAST8  "d"
0158 #define SCNiLEAST8  "i"
0159 #define SCNdFAST8   "d"
0160 #define SCNiFAST8   "i"
0161 
0162 #define SCNd16       "hd"
0163 #define SCNi16       "hi"
0164 #define SCNdLEAST16  "hd"
0165 #define SCNiLEAST16  "hi"
0166 #define SCNdFAST16   "hd"
0167 #define SCNiFAST16   "hi"
0168 
0169 #define SCNd32       "ld"
0170 #define SCNi32       "li"
0171 #define SCNdLEAST32  "ld"
0172 #define SCNiLEAST32  "li"
0173 #define SCNdFAST32   "ld"
0174 #define SCNiFAST32   "li"
0175 
0176 #define SCNd64       "I64d"
0177 #define SCNi64       "I64i"
0178 #define SCNdLEAST64  "I64d"
0179 #define SCNiLEAST64  "I64i"
0180 #define SCNdFAST64   "I64d"
0181 #define SCNiFAST64   "I64i"
0182 
0183 #define SCNdMAX     "I64d"
0184 #define SCNiMAX     "I64i"
0185 
0186 #ifdef _WIN64 // [
0187 #  define SCNdPTR     "I64d"
0188 #  define SCNiPTR     "I64i"
0189 #else  // _WIN64 ][
0190 #  define SCNdPTR     "ld"
0191 #  define SCNiPTR     "li"
0192 #endif  // _WIN64 ]
0193 
0194 // The fscanf macros for unsigned integers are:
0195 #define SCNo8       "o"
0196 #define SCNu8       "u"
0197 #define SCNx8       "x"
0198 #define SCNX8       "X"
0199 #define SCNoLEAST8  "o"
0200 #define SCNuLEAST8  "u"
0201 #define SCNxLEAST8  "x"
0202 #define SCNXLEAST8  "X"
0203 #define SCNoFAST8   "o"
0204 #define SCNuFAST8   "u"
0205 #define SCNxFAST8   "x"
0206 #define SCNXFAST8   "X"
0207 
0208 #define SCNo16       "ho"
0209 #define SCNu16       "hu"
0210 #define SCNx16       "hx"
0211 #define SCNX16       "hX"
0212 #define SCNoLEAST16  "ho"
0213 #define SCNuLEAST16  "hu"
0214 #define SCNxLEAST16  "hx"
0215 #define SCNXLEAST16  "hX"
0216 #define SCNoFAST16   "ho"
0217 #define SCNuFAST16   "hu"
0218 #define SCNxFAST16   "hx"
0219 #define SCNXFAST16   "hX"
0220 
0221 #define SCNo32       "lo"
0222 #define SCNu32       "lu"
0223 #define SCNx32       "lx"
0224 #define SCNX32       "lX"
0225 #define SCNoLEAST32  "lo"
0226 #define SCNuLEAST32  "lu"
0227 #define SCNxLEAST32  "lx"
0228 #define SCNXLEAST32  "lX"
0229 #define SCNoFAST32   "lo"
0230 #define SCNuFAST32   "lu"
0231 #define SCNxFAST32   "lx"
0232 #define SCNXFAST32   "lX"
0233 
0234 #define SCNo64       "I64o"
0235 #define SCNu64       "I64u"
0236 #define SCNx64       "I64x"
0237 #define SCNX64       "I64X"
0238 #define SCNoLEAST64  "I64o"
0239 #define SCNuLEAST64  "I64u"
0240 #define SCNxLEAST64  "I64x"
0241 #define SCNXLEAST64  "I64X"
0242 #define SCNoFAST64   "I64o"
0243 #define SCNuFAST64   "I64u"
0244 #define SCNxFAST64   "I64x"
0245 #define SCNXFAST64   "I64X"
0246 
0247 #define SCNoMAX     "I64o"
0248 #define SCNuMAX     "I64u"
0249 #define SCNxMAX     "I64x"
0250 #define SCNXMAX     "I64X"
0251 
0252 #ifdef _WIN64 // [
0253 #  define SCNoPTR     "I64o"
0254 #  define SCNuPTR     "I64u"
0255 #  define SCNxPTR     "I64x"
0256 #  define SCNXPTR     "I64X"
0257 #else  // _WIN64 ][
0258 #  define SCNoPTR     "lo"
0259 #  define SCNuPTR     "lu"
0260 #  define SCNxPTR     "lx"
0261 #  define SCNXPTR     "lX"
0262 #endif  // _WIN64 ]
0263 
0264 #endif // __STDC_FORMAT_MACROS ]
0265 
0266 // 7.8.2 Functions for greatest-width integer types
0267 
0268 // 7.8.2.1 The imaxabs function
0269 #define imaxabs _abs64
0270 
0271 // 7.8.2.2 The imaxdiv function
0272 
0273 // This is modified version of div() function from Microsoft's div.c found
0274 // in %MSVC.NET%\crt\src\div.c
0275 #ifdef STATIC_IMAXDIV // [
0276 static
0277 #else // STATIC_IMAXDIV ][
0278 _inline
0279 #endif // STATIC_IMAXDIV ]
0280 imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
0281 {
0282    imaxdiv_t result;
0283 
0284    result.quot = numer / denom;
0285    result.rem = numer % denom;
0286 
0287    if (numer < 0 && result.rem > 0) {
0288       // did division wrong; must fix up
0289       ++result.quot;
0290       result.rem -= denom;
0291    }
0292 
0293    return result;
0294 }
0295 
0296 // 7.8.2.3 The strtoimax and strtoumax functions
0297 #define strtoimax _strtoi64
0298 #define strtoumax _strtoui64
0299 
0300 // 7.8.2.4 The wcstoimax and wcstoumax functions
0301 #define wcstoimax _wcstoi64
0302 #define wcstoumax _wcstoui64
0303 
0304 #endif // _MSC_VER
0305 
0306 #endif // _MSC_INTTYPES_H_ ]