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