1*bf6039f0SWarner Losh // ISO C9x compliant stdint.h for Microsoft Visual Studio 2*bf6039f0SWarner Losh // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3*bf6039f0SWarner Losh // 4*bf6039f0SWarner Losh // Copyright (c) 2006-2008 Alexander Chemeris 5*bf6039f0SWarner Losh // 6*bf6039f0SWarner Losh // Redistribution and use in source and binary forms, with or without 7*bf6039f0SWarner Losh // modification, are permitted provided that the following conditions are met: 8*bf6039f0SWarner Losh // 9*bf6039f0SWarner Losh // 1. Redistributions of source code must retain the above copyright notice, 10*bf6039f0SWarner Losh // this list of conditions and the following disclaimer. 11*bf6039f0SWarner Losh // 12*bf6039f0SWarner Losh // 2. Redistributions in binary form must reproduce the above copyright 13*bf6039f0SWarner Losh // notice, this list of conditions and the following disclaimer in the 14*bf6039f0SWarner Losh // documentation and/or other materials provided with the distribution. 15*bf6039f0SWarner Losh // 16*bf6039f0SWarner Losh // 3. The name of the author may be used to endorse or promote products 17*bf6039f0SWarner Losh // derived from this software without specific prior written permission. 18*bf6039f0SWarner Losh // 19*bf6039f0SWarner Losh // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20*bf6039f0SWarner Losh // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21*bf6039f0SWarner Losh // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 22*bf6039f0SWarner Losh // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23*bf6039f0SWarner Losh // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24*bf6039f0SWarner Losh // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25*bf6039f0SWarner Losh // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26*bf6039f0SWarner Losh // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27*bf6039f0SWarner Losh // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28*bf6039f0SWarner Losh // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29*bf6039f0SWarner Losh // 30*bf6039f0SWarner Losh /////////////////////////////////////////////////////////////////////////////// 31*bf6039f0SWarner Losh 32*bf6039f0SWarner Losh #ifndef _MSC_VER // [ 33*bf6039f0SWarner Losh #error "Use this header only with Microsoft Visual C++ compilers!" 34*bf6039f0SWarner Losh #endif // _MSC_VER ] 35*bf6039f0SWarner Losh 36*bf6039f0SWarner Losh #ifndef _MSC_STDINT_H_ // [ 37*bf6039f0SWarner Losh #define _MSC_STDINT_H_ 38*bf6039f0SWarner Losh 39*bf6039f0SWarner Losh #if _MSC_VER > 1000 40*bf6039f0SWarner Losh #pragma once 41*bf6039f0SWarner Losh #endif 42*bf6039f0SWarner Losh 43*bf6039f0SWarner Losh #include <limits.h> 44*bf6039f0SWarner Losh 45*bf6039f0SWarner Losh // For Visual Studio 6 in C++ mode and for many Visual Studio versions when 46*bf6039f0SWarner Losh // compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}' 47*bf6039f0SWarner Losh // or compiler give many errors like this: 48*bf6039f0SWarner Losh // error C2733: second C linkage of overloaded function 'wmemchr' not allowed 49*bf6039f0SWarner Losh #ifdef __cplusplus 50*bf6039f0SWarner Losh extern "C" { 51*bf6039f0SWarner Losh #endif 52*bf6039f0SWarner Losh # include <wchar.h> 53*bf6039f0SWarner Losh #ifdef __cplusplus 54*bf6039f0SWarner Losh } 55*bf6039f0SWarner Losh #endif 56*bf6039f0SWarner Losh 57*bf6039f0SWarner Losh // Define _W64 macros to mark types changing their size, like intptr_t. 58*bf6039f0SWarner Losh #ifndef _W64 59*bf6039f0SWarner Losh # if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 60*bf6039f0SWarner Losh # define _W64 __w64 61*bf6039f0SWarner Losh # else 62*bf6039f0SWarner Losh # define _W64 63*bf6039f0SWarner Losh # endif 64*bf6039f0SWarner Losh #endif 65*bf6039f0SWarner Losh 66*bf6039f0SWarner Losh 67*bf6039f0SWarner Losh // 7.18.1 Integer types 68*bf6039f0SWarner Losh 69*bf6039f0SWarner Losh // 7.18.1.1 Exact-width integer types 70*bf6039f0SWarner Losh 71*bf6039f0SWarner Losh // Visual Studio 6 and Embedded Visual C++ 4 doesn't 72*bf6039f0SWarner Losh // realize that, e.g. char has the same size as __int8 73*bf6039f0SWarner Losh // so we give up on __intX for them. 74*bf6039f0SWarner Losh #if (_MSC_VER < 1300) 75*bf6039f0SWarner Losh typedef signed char int8_t; 76*bf6039f0SWarner Losh typedef signed short int16_t; 77*bf6039f0SWarner Losh typedef signed int int32_t; 78*bf6039f0SWarner Losh typedef unsigned char uint8_t; 79*bf6039f0SWarner Losh typedef unsigned short uint16_t; 80*bf6039f0SWarner Losh typedef unsigned int uint32_t; 81*bf6039f0SWarner Losh #else 82*bf6039f0SWarner Losh typedef signed __int8 int8_t; 83*bf6039f0SWarner Losh typedef signed __int16 int16_t; 84*bf6039f0SWarner Losh typedef signed __int32 int32_t; 85*bf6039f0SWarner Losh typedef unsigned __int8 uint8_t; 86*bf6039f0SWarner Losh typedef unsigned __int16 uint16_t; 87*bf6039f0SWarner Losh typedef unsigned __int32 uint32_t; 88*bf6039f0SWarner Losh #endif 89*bf6039f0SWarner Losh typedef signed __int64 int64_t; 90*bf6039f0SWarner Losh typedef unsigned __int64 uint64_t; 91*bf6039f0SWarner Losh 92*bf6039f0SWarner Losh 93*bf6039f0SWarner Losh // 7.18.1.2 Minimum-width integer types 94*bf6039f0SWarner Losh typedef int8_t int_least8_t; 95*bf6039f0SWarner Losh typedef int16_t int_least16_t; 96*bf6039f0SWarner Losh typedef int32_t int_least32_t; 97*bf6039f0SWarner Losh typedef int64_t int_least64_t; 98*bf6039f0SWarner Losh typedef uint8_t uint_least8_t; 99*bf6039f0SWarner Losh typedef uint16_t uint_least16_t; 100*bf6039f0SWarner Losh typedef uint32_t uint_least32_t; 101*bf6039f0SWarner Losh typedef uint64_t uint_least64_t; 102*bf6039f0SWarner Losh 103*bf6039f0SWarner Losh // 7.18.1.3 Fastest minimum-width integer types 104*bf6039f0SWarner Losh typedef int8_t int_fast8_t; 105*bf6039f0SWarner Losh typedef int16_t int_fast16_t; 106*bf6039f0SWarner Losh typedef int32_t int_fast32_t; 107*bf6039f0SWarner Losh typedef int64_t int_fast64_t; 108*bf6039f0SWarner Losh typedef uint8_t uint_fast8_t; 109*bf6039f0SWarner Losh typedef uint16_t uint_fast16_t; 110*bf6039f0SWarner Losh typedef uint32_t uint_fast32_t; 111*bf6039f0SWarner Losh typedef uint64_t uint_fast64_t; 112*bf6039f0SWarner Losh 113*bf6039f0SWarner Losh // 7.18.1.4 Integer types capable of holding object pointers 114*bf6039f0SWarner Losh #ifdef _WIN64 // [ 115*bf6039f0SWarner Losh typedef signed __int64 intptr_t; 116*bf6039f0SWarner Losh typedef unsigned __int64 uintptr_t; 117*bf6039f0SWarner Losh #else // _WIN64 ][ 118*bf6039f0SWarner Losh typedef _W64 signed int intptr_t; 119*bf6039f0SWarner Losh typedef _W64 unsigned int uintptr_t; 120*bf6039f0SWarner Losh #endif // _WIN64 ] 121*bf6039f0SWarner Losh 122*bf6039f0SWarner Losh // 7.18.1.5 Greatest-width integer types 123*bf6039f0SWarner Losh typedef int64_t intmax_t; 124*bf6039f0SWarner Losh typedef uint64_t uintmax_t; 125*bf6039f0SWarner Losh 126*bf6039f0SWarner Losh 127*bf6039f0SWarner Losh // 7.18.2 Limits of specified-width integer types 128*bf6039f0SWarner Losh 129*bf6039f0SWarner Losh #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 130*bf6039f0SWarner Losh 131*bf6039f0SWarner Losh // 7.18.2.1 Limits of exact-width integer types 132*bf6039f0SWarner Losh #define INT8_MIN ((int8_t)_I8_MIN) 133*bf6039f0SWarner Losh #define INT8_MAX _I8_MAX 134*bf6039f0SWarner Losh #define INT16_MIN ((int16_t)_I16_MIN) 135*bf6039f0SWarner Losh #define INT16_MAX _I16_MAX 136*bf6039f0SWarner Losh #define INT32_MIN ((int32_t)_I32_MIN) 137*bf6039f0SWarner Losh #define INT32_MAX _I32_MAX 138*bf6039f0SWarner Losh #define INT64_MIN ((int64_t)_I64_MIN) 139*bf6039f0SWarner Losh #define INT64_MAX _I64_MAX 140*bf6039f0SWarner Losh #define UINT8_MAX _UI8_MAX 141*bf6039f0SWarner Losh #define UINT16_MAX _UI16_MAX 142*bf6039f0SWarner Losh #define UINT32_MAX _UI32_MAX 143*bf6039f0SWarner Losh #define UINT64_MAX _UI64_MAX 144*bf6039f0SWarner Losh 145*bf6039f0SWarner Losh // 7.18.2.2 Limits of minimum-width integer types 146*bf6039f0SWarner Losh #define INT_LEAST8_MIN INT8_MIN 147*bf6039f0SWarner Losh #define INT_LEAST8_MAX INT8_MAX 148*bf6039f0SWarner Losh #define INT_LEAST16_MIN INT16_MIN 149*bf6039f0SWarner Losh #define INT_LEAST16_MAX INT16_MAX 150*bf6039f0SWarner Losh #define INT_LEAST32_MIN INT32_MIN 151*bf6039f0SWarner Losh #define INT_LEAST32_MAX INT32_MAX 152*bf6039f0SWarner Losh #define INT_LEAST64_MIN INT64_MIN 153*bf6039f0SWarner Losh #define INT_LEAST64_MAX INT64_MAX 154*bf6039f0SWarner Losh #define UINT_LEAST8_MAX UINT8_MAX 155*bf6039f0SWarner Losh #define UINT_LEAST16_MAX UINT16_MAX 156*bf6039f0SWarner Losh #define UINT_LEAST32_MAX UINT32_MAX 157*bf6039f0SWarner Losh #define UINT_LEAST64_MAX UINT64_MAX 158*bf6039f0SWarner Losh 159*bf6039f0SWarner Losh // 7.18.2.3 Limits of fastest minimum-width integer types 160*bf6039f0SWarner Losh #define INT_FAST8_MIN INT8_MIN 161*bf6039f0SWarner Losh #define INT_FAST8_MAX INT8_MAX 162*bf6039f0SWarner Losh #define INT_FAST16_MIN INT16_MIN 163*bf6039f0SWarner Losh #define INT_FAST16_MAX INT16_MAX 164*bf6039f0SWarner Losh #define INT_FAST32_MIN INT32_MIN 165*bf6039f0SWarner Losh #define INT_FAST32_MAX INT32_MAX 166*bf6039f0SWarner Losh #define INT_FAST64_MIN INT64_MIN 167*bf6039f0SWarner Losh #define INT_FAST64_MAX INT64_MAX 168*bf6039f0SWarner Losh #define UINT_FAST8_MAX UINT8_MAX 169*bf6039f0SWarner Losh #define UINT_FAST16_MAX UINT16_MAX 170*bf6039f0SWarner Losh #define UINT_FAST32_MAX UINT32_MAX 171*bf6039f0SWarner Losh #define UINT_FAST64_MAX UINT64_MAX 172*bf6039f0SWarner Losh 173*bf6039f0SWarner Losh // 7.18.2.4 Limits of integer types capable of holding object pointers 174*bf6039f0SWarner Losh #ifdef _WIN64 // [ 175*bf6039f0SWarner Losh # define INTPTR_MIN INT64_MIN 176*bf6039f0SWarner Losh # define INTPTR_MAX INT64_MAX 177*bf6039f0SWarner Losh # define UINTPTR_MAX UINT64_MAX 178*bf6039f0SWarner Losh #else // _WIN64 ][ 179*bf6039f0SWarner Losh # define INTPTR_MIN INT32_MIN 180*bf6039f0SWarner Losh # define INTPTR_MAX INT32_MAX 181*bf6039f0SWarner Losh # define UINTPTR_MAX UINT32_MAX 182*bf6039f0SWarner Losh #endif // _WIN64 ] 183*bf6039f0SWarner Losh 184*bf6039f0SWarner Losh // 7.18.2.5 Limits of greatest-width integer types 185*bf6039f0SWarner Losh #define INTMAX_MIN INT64_MIN 186*bf6039f0SWarner Losh #define INTMAX_MAX INT64_MAX 187*bf6039f0SWarner Losh #define UINTMAX_MAX UINT64_MAX 188*bf6039f0SWarner Losh 189*bf6039f0SWarner Losh // 7.18.3 Limits of other integer types 190*bf6039f0SWarner Losh 191*bf6039f0SWarner Losh #ifdef _WIN64 // [ 192*bf6039f0SWarner Losh # define PTRDIFF_MIN _I64_MIN 193*bf6039f0SWarner Losh # define PTRDIFF_MAX _I64_MAX 194*bf6039f0SWarner Losh #else // _WIN64 ][ 195*bf6039f0SWarner Losh # define PTRDIFF_MIN _I32_MIN 196*bf6039f0SWarner Losh # define PTRDIFF_MAX _I32_MAX 197*bf6039f0SWarner Losh #endif // _WIN64 ] 198*bf6039f0SWarner Losh 199*bf6039f0SWarner Losh #define SIG_ATOMIC_MIN INT_MIN 200*bf6039f0SWarner Losh #define SIG_ATOMIC_MAX INT_MAX 201*bf6039f0SWarner Losh 202*bf6039f0SWarner Losh #ifndef SIZE_MAX // [ 203*bf6039f0SWarner Losh # ifdef _WIN64 // [ 204*bf6039f0SWarner Losh # define SIZE_MAX _UI64_MAX 205*bf6039f0SWarner Losh # else // _WIN64 ][ 206*bf6039f0SWarner Losh # define SIZE_MAX _UI32_MAX 207*bf6039f0SWarner Losh # endif // _WIN64 ] 208*bf6039f0SWarner Losh #endif // SIZE_MAX ] 209*bf6039f0SWarner Losh 210*bf6039f0SWarner Losh // WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h> 211*bf6039f0SWarner Losh #ifndef WCHAR_MIN // [ 212*bf6039f0SWarner Losh # define WCHAR_MIN 0 213*bf6039f0SWarner Losh #endif // WCHAR_MIN ] 214*bf6039f0SWarner Losh #ifndef WCHAR_MAX // [ 215*bf6039f0SWarner Losh # define WCHAR_MAX _UI16_MAX 216*bf6039f0SWarner Losh #endif // WCHAR_MAX ] 217*bf6039f0SWarner Losh 218*bf6039f0SWarner Losh #define WINT_MIN 0 219*bf6039f0SWarner Losh #define WINT_MAX _UI16_MAX 220*bf6039f0SWarner Losh 221*bf6039f0SWarner Losh #endif // __STDC_LIMIT_MACROS ] 222*bf6039f0SWarner Losh 223*bf6039f0SWarner Losh 224*bf6039f0SWarner Losh // 7.18.4 Limits of other integer types 225*bf6039f0SWarner Losh 226*bf6039f0SWarner Losh #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 227*bf6039f0SWarner Losh 228*bf6039f0SWarner Losh // 7.18.4.1 Macros for minimum-width integer constants 229*bf6039f0SWarner Losh 230*bf6039f0SWarner Losh #define INT8_C(val) val##i8 231*bf6039f0SWarner Losh #define INT16_C(val) val##i16 232*bf6039f0SWarner Losh #define INT32_C(val) val##i32 233*bf6039f0SWarner Losh #define INT64_C(val) val##i64 234*bf6039f0SWarner Losh 235*bf6039f0SWarner Losh #define UINT8_C(val) val##ui8 236*bf6039f0SWarner Losh #define UINT16_C(val) val##ui16 237*bf6039f0SWarner Losh #define UINT32_C(val) val##ui32 238*bf6039f0SWarner Losh #define UINT64_C(val) val##ui64 239*bf6039f0SWarner Losh 240*bf6039f0SWarner Losh // 7.18.4.2 Macros for greatest-width integer constants 241*bf6039f0SWarner Losh #define INTMAX_C INT64_C 242*bf6039f0SWarner Losh #define UINTMAX_C UINT64_C 243*bf6039f0SWarner Losh 244*bf6039f0SWarner Losh #endif // __STDC_CONSTANT_MACROS ] 245*bf6039f0SWarner Losh 246*bf6039f0SWarner Losh 247*bf6039f0SWarner Losh #endif // _MSC_STDINT_H_ ] 248