File indexing completed on 2024-12-15 04:11:43

0001 // ISO C9x  compliant stdint.h for Microsoft Visual Studio
0002 // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 
0003 // 
0004 //  Copyright (c) 2006-2008 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 #endif // _MSC_VER ]
0035 
0036 #ifndef _MSC_STDINT_H_ // [
0037 #define _MSC_STDINT_H_
0038 
0039 #if _MSC_VER > 1000
0040 #pragma once
0041 #endif
0042 
0043 #include <limits.h>
0044 
0045 // For Visual Studio 6 in C++ mode wrap <wchar.h> include with 'extern "C++" {}'
0046 // or compiler give many errors like this:
0047 //   error C2733: second C linkage of overloaded function 'wmemchr' not allowed
0048 #if (_MSC_VER < 1300) && defined(__cplusplus)
0049    extern "C++" {
0050 #endif 
0051 #     include <wchar.h>
0052 #if (_MSC_VER < 1300) && defined(__cplusplus)
0053    }
0054 #endif
0055 
0056 // Define _W64 macros to mark types changing their size, like intptr_t.
0057 #ifndef _W64
0058 #  if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
0059 #     define _W64 __w64
0060 #  else
0061 #     define _W64
0062 #  endif
0063 #endif
0064 
0065 
0066 // 7.18.1 Integer types
0067 
0068 // 7.18.1.1 Exact-width integer types
0069 typedef __int8            int8_t;
0070 typedef __int16           int16_t;
0071 typedef __int32           int32_t;
0072 typedef __int64           int64_t;
0073 typedef unsigned __int8   uint8_t;
0074 typedef unsigned __int16  uint16_t;
0075 typedef unsigned __int32  uint32_t;
0076 typedef unsigned __int64  uint64_t;
0077 
0078 // 7.18.1.2 Minimum-width integer types
0079 typedef int8_t    int_least8_t;
0080 typedef int16_t   int_least16_t;
0081 typedef int32_t   int_least32_t;
0082 typedef int64_t   int_least64_t;
0083 typedef uint8_t   uint_least8_t;
0084 typedef uint16_t  uint_least16_t;
0085 typedef uint32_t  uint_least32_t;
0086 typedef uint64_t  uint_least64_t;
0087 
0088 // 7.18.1.3 Fastest minimum-width integer types
0089 typedef int8_t    int_fast8_t;
0090 typedef int16_t   int_fast16_t;
0091 typedef int32_t   int_fast32_t;
0092 typedef int64_t   int_fast64_t;
0093 typedef uint8_t   uint_fast8_t;
0094 typedef uint16_t  uint_fast16_t;
0095 typedef uint32_t  uint_fast32_t;
0096 typedef uint64_t  uint_fast64_t;
0097 
0098 // 7.18.1.4 Integer types capable of holding object pointers
0099 #ifdef _WIN64 // [
0100    typedef __int64           intptr_t;
0101    typedef unsigned __int64  uintptr_t;
0102 #else // _WIN64 ][
0103    typedef _W64 int               intptr_t;
0104    typedef _W64 unsigned int      uintptr_t;
0105 #endif // _WIN64 ]
0106 
0107 // 7.18.1.5 Greatest-width integer types
0108 typedef int64_t   intmax_t;
0109 typedef uint64_t  uintmax_t;
0110 
0111 
0112 // 7.18.2 Limits of specified-width integer types
0113 
0114 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [   See footnote 220 at page 257 and footnote 221 at page 259
0115 
0116 // 7.18.2.1 Limits of exact-width integer types
0117 #define INT8_MIN     ((int8_t)_I8_MIN)
0118 #define INT8_MAX     _I8_MAX
0119 #define INT16_MIN    ((int16_t)_I16_MIN)
0120 #define INT16_MAX    _I16_MAX
0121 #define INT32_MIN    ((int32_t)_I32_MIN)
0122 #define INT32_MAX    _I32_MAX
0123 #define INT64_MIN    ((int64_t)_I64_MIN)
0124 #define INT64_MAX    _I64_MAX
0125 #define UINT8_MAX    _UI8_MAX
0126 #define UINT16_MAX   _UI16_MAX
0127 #define UINT32_MAX   _UI32_MAX
0128 #define UINT64_MAX   _UI64_MAX
0129 
0130 // 7.18.2.2 Limits of minimum-width integer types
0131 #define INT_LEAST8_MIN    INT8_MIN
0132 #define INT_LEAST8_MAX    INT8_MAX
0133 #define INT_LEAST16_MIN   INT16_MIN
0134 #define INT_LEAST16_MAX   INT16_MAX
0135 #define INT_LEAST32_MIN   INT32_MIN
0136 #define INT_LEAST32_MAX   INT32_MAX
0137 #define INT_LEAST64_MIN   INT64_MIN
0138 #define INT_LEAST64_MAX   INT64_MAX
0139 #define UINT_LEAST8_MAX   UINT8_MAX
0140 #define UINT_LEAST16_MAX  UINT16_MAX
0141 #define UINT_LEAST32_MAX  UINT32_MAX
0142 #define UINT_LEAST64_MAX  UINT64_MAX
0143 
0144 // 7.18.2.3 Limits of fastest minimum-width integer types
0145 #define INT_FAST8_MIN    INT8_MIN
0146 #define INT_FAST8_MAX    INT8_MAX
0147 #define INT_FAST16_MIN   INT16_MIN
0148 #define INT_FAST16_MAX   INT16_MAX
0149 #define INT_FAST32_MIN   INT32_MIN
0150 #define INT_FAST32_MAX   INT32_MAX
0151 #define INT_FAST64_MIN   INT64_MIN
0152 #define INT_FAST64_MAX   INT64_MAX
0153 #define UINT_FAST8_MAX   UINT8_MAX
0154 #define UINT_FAST16_MAX  UINT16_MAX
0155 #define UINT_FAST32_MAX  UINT32_MAX
0156 #define UINT_FAST64_MAX  UINT64_MAX
0157 
0158 // 7.18.2.4 Limits of integer types capable of holding object pointers
0159 #ifdef _WIN64 // [
0160 #  define INTPTR_MIN   INT64_MIN
0161 #  define INTPTR_MAX   INT64_MAX
0162 #  define UINTPTR_MAX  UINT64_MAX
0163 #else // _WIN64 ][
0164 #  define INTPTR_MIN   INT32_MIN
0165 #  define INTPTR_MAX   INT32_MAX
0166 #  define UINTPTR_MAX  UINT32_MAX
0167 #endif // _WIN64 ]
0168 
0169 // 7.18.2.5 Limits of greatest-width integer types
0170 #define INTMAX_MIN   INT64_MIN
0171 #define INTMAX_MAX   INT64_MAX
0172 #define UINTMAX_MAX  UINT64_MAX
0173 
0174 // 7.18.3 Limits of other integer types
0175 
0176 #ifdef _WIN64 // [
0177 #  define PTRDIFF_MIN  _I64_MIN
0178 #  define PTRDIFF_MAX  _I64_MAX
0179 #else  // _WIN64 ][
0180 #  define PTRDIFF_MIN  _I32_MIN
0181 #  define PTRDIFF_MAX  _I32_MAX
0182 #endif  // _WIN64 ]
0183 
0184 #define SIG_ATOMIC_MIN  INT_MIN
0185 #define SIG_ATOMIC_MAX  INT_MAX
0186 
0187 #ifndef SIZE_MAX // [
0188 #  ifdef _WIN64 // [
0189 #     define SIZE_MAX  _UI64_MAX
0190 #  else // _WIN64 ][
0191 #     define SIZE_MAX  _UI32_MAX
0192 #  endif // _WIN64 ]
0193 #endif // SIZE_MAX ]
0194 
0195 // WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
0196 #ifndef WCHAR_MIN // [
0197 #  define WCHAR_MIN  0
0198 #endif  // WCHAR_MIN ]
0199 #ifndef WCHAR_MAX // [
0200 #  define WCHAR_MAX  _UI16_MAX
0201 #endif  // WCHAR_MAX ]
0202 
0203 #define WINT_MIN  0
0204 #define WINT_MAX  _UI16_MAX
0205 
0206 #endif // __STDC_LIMIT_MACROS ]
0207 
0208 
0209 // 7.18.4 Limits of other integer types
0210 
0211 #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [   See footnote 224 at page 260
0212 
0213 // 7.18.4.1 Macros for minimum-width integer constants
0214 
0215 #define INT8_C(val)  val##i8
0216 #define INT16_C(val) val##i16
0217 #define INT32_C(val) val##i32
0218 #define INT64_C(val) val##i64
0219 
0220 #define UINT8_C(val)  val##ui8
0221 #define UINT16_C(val) val##ui16
0222 #define UINT32_C(val) val##ui32
0223 #define UINT64_C(val) val##ui64
0224 
0225 // 7.18.4.2 Macros for greatest-width integer constants
0226 #define INTMAX_C   INT64_C
0227 #define UINTMAX_C  UINT64_C
0228 
0229 #endif // __STDC_CONSTANT_MACROS ]
0230 
0231 
0232 #endif // _MSC_STDINT_H_ ]