michael@0: // ISO C9x compliant inttypes.h for Microsoft Visual Studio michael@0: // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 michael@0: // michael@0: // Copyright (c) 2006 Alexander Chemeris michael@0: // michael@0: // Redistribution and use in source and binary forms, with or without michael@0: // modification, are permitted provided that the following conditions are met: michael@0: // michael@0: // 1. Redistributions of source code must retain the above copyright notice, michael@0: // this list of conditions and the following disclaimer. michael@0: // michael@0: // 2. Redistributions in binary form must reproduce the above copyright michael@0: // notice, this list of conditions and the following disclaimer in the michael@0: // documentation and/or other materials provided with the distribution. michael@0: // michael@0: // 3. The name of the author may be used to endorse or promote products michael@0: // derived from this software without specific prior written permission. michael@0: // michael@0: // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED michael@0: // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF michael@0: // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO michael@0: // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; michael@0: // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, michael@0: // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR michael@0: // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF michael@0: // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: // michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifndef _MSC_VER // [ michael@0: #error "Use this header only with Microsoft Visual C++ compilers!" michael@0: #endif // _MSC_VER ] michael@0: michael@0: #ifndef _MSC_INTTYPES_H_ // [ michael@0: #define _MSC_INTTYPES_H_ michael@0: michael@0: #if _MSC_VER > 1000 michael@0: #pragma once michael@0: #endif michael@0: michael@0: #include michael@0: michael@0: // 7.8 Format conversion of integer types michael@0: michael@0: typedef struct { michael@0: intmax_t quot; michael@0: intmax_t rem; michael@0: } imaxdiv_t; michael@0: michael@0: // 7.8.1 Macros for format specifiers michael@0: michael@0: #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 michael@0: michael@0: // The fprintf macros for signed integers are: michael@0: #define PRId8 "d" michael@0: #define PRIi8 "i" michael@0: #define PRIdLEAST8 "d" michael@0: #define PRIiLEAST8 "i" michael@0: #define PRIdFAST8 "d" michael@0: #define PRIiFAST8 "i" michael@0: michael@0: #define PRId16 "hd" michael@0: #define PRIi16 "hi" michael@0: #define PRIdLEAST16 "hd" michael@0: #define PRIiLEAST16 "hi" michael@0: #define PRIdFAST16 "hd" michael@0: #define PRIiFAST16 "hi" michael@0: michael@0: #define PRId32 "I32d" michael@0: #define PRIi32 "I32i" michael@0: #define PRIdLEAST32 "I32d" michael@0: #define PRIiLEAST32 "I32i" michael@0: #define PRIdFAST32 "I32d" michael@0: #define PRIiFAST32 "I32i" michael@0: michael@0: #define PRId64 "I64d" michael@0: #define PRIi64 "I64i" michael@0: #define PRIdLEAST64 "I64d" michael@0: #define PRIiLEAST64 "I64i" michael@0: #define PRIdFAST64 "I64d" michael@0: #define PRIiFAST64 "I64i" michael@0: michael@0: #define PRIdMAX "I64d" michael@0: #define PRIiMAX "I64i" michael@0: michael@0: #define PRIdPTR "Id" michael@0: #define PRIiPTR "Ii" michael@0: michael@0: // The fprintf macros for unsigned integers are: michael@0: #define PRIo8 "o" michael@0: #define PRIu8 "u" michael@0: #define PRIx8 "x" michael@0: #define PRIX8 "X" michael@0: #define PRIoLEAST8 "o" michael@0: #define PRIuLEAST8 "u" michael@0: #define PRIxLEAST8 "x" michael@0: #define PRIXLEAST8 "X" michael@0: #define PRIoFAST8 "o" michael@0: #define PRIuFAST8 "u" michael@0: #define PRIxFAST8 "x" michael@0: #define PRIXFAST8 "X" michael@0: michael@0: #define PRIo16 "ho" michael@0: #define PRIu16 "hu" michael@0: #define PRIx16 "hx" michael@0: #define PRIX16 "hX" michael@0: #define PRIoLEAST16 "ho" michael@0: #define PRIuLEAST16 "hu" michael@0: #define PRIxLEAST16 "hx" michael@0: #define PRIXLEAST16 "hX" michael@0: #define PRIoFAST16 "ho" michael@0: #define PRIuFAST16 "hu" michael@0: #define PRIxFAST16 "hx" michael@0: #define PRIXFAST16 "hX" michael@0: michael@0: #define PRIo32 "I32o" michael@0: #define PRIu32 "I32u" michael@0: #define PRIx32 "I32x" michael@0: #define PRIX32 "I32X" michael@0: #define PRIoLEAST32 "I32o" michael@0: #define PRIuLEAST32 "I32u" michael@0: #define PRIxLEAST32 "I32x" michael@0: #define PRIXLEAST32 "I32X" michael@0: #define PRIoFAST32 "I32o" michael@0: #define PRIuFAST32 "I32u" michael@0: #define PRIxFAST32 "I32x" michael@0: #define PRIXFAST32 "I32X" michael@0: michael@0: #define PRIo64 "I64o" michael@0: #define PRIu64 "I64u" michael@0: #define PRIx64 "I64x" michael@0: #define PRIX64 "I64X" michael@0: #define PRIoLEAST64 "I64o" michael@0: #define PRIuLEAST64 "I64u" michael@0: #define PRIxLEAST64 "I64x" michael@0: #define PRIXLEAST64 "I64X" michael@0: #define PRIoFAST64 "I64o" michael@0: #define PRIuFAST64 "I64u" michael@0: #define PRIxFAST64 "I64x" michael@0: #define PRIXFAST64 "I64X" michael@0: michael@0: #define PRIoMAX "I64o" michael@0: #define PRIuMAX "I64u" michael@0: #define PRIxMAX "I64x" michael@0: #define PRIXMAX "I64X" michael@0: michael@0: #define PRIoPTR "Io" michael@0: #define PRIuPTR "Iu" michael@0: #define PRIxPTR "Ix" michael@0: #define PRIXPTR "IX" michael@0: michael@0: // DO NOT SUPPORT THE scanf MACROS! See the comment at the top of michael@0: // IntegerPrintfMacros.h. michael@0: michael@0: #endif // __STDC_FORMAT_MACROS ] michael@0: michael@0: // 7.8.2 Functions for greatest-width integer types michael@0: michael@0: // 7.8.2.1 The imaxabs function michael@0: #define imaxabs _abs64 michael@0: michael@0: // 7.8.2.2 The imaxdiv function michael@0: michael@0: // This is modified version of div() function from Microsoft's div.c found michael@0: // in %MSVC.NET%\crt\src\div.c michael@0: #ifdef STATIC_IMAXDIV // [ michael@0: static michael@0: #else // STATIC_IMAXDIV ][ michael@0: _inline michael@0: #endif // STATIC_IMAXDIV ] michael@0: imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) michael@0: { michael@0: imaxdiv_t result; michael@0: michael@0: result.quot = numer / denom; michael@0: result.rem = numer % denom; michael@0: michael@0: if (numer < 0 && result.rem > 0) { michael@0: // did division wrong; must fix up michael@0: ++result.quot; michael@0: result.rem -= denom; michael@0: } michael@0: michael@0: return result; michael@0: } michael@0: michael@0: // 7.8.2.3 The strtoimax and strtoumax functions michael@0: #define strtoimax _strtoi64 michael@0: #define strtoumax _strtoui64 michael@0: michael@0: // 7.8.2.4 The wcstoimax and wcstoumax functions michael@0: #define wcstoimax _wcstoi64 michael@0: #define wcstoumax _wcstoui64 michael@0: michael@0: michael@0: #endif // _MSC_INTTYPES_H_ ]