17777dab0Sopenharmony_ci// ISO C9x  compliant stdint.h for Microsoft Visual Studio
27777dab0Sopenharmony_ci// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
37777dab0Sopenharmony_ci//
47777dab0Sopenharmony_ci//  Copyright (c) 2006-2008 Alexander Chemeris
57777dab0Sopenharmony_ci//
67777dab0Sopenharmony_ci// Redistribution and use in source and binary forms, with or without
77777dab0Sopenharmony_ci// modification, are permitted provided that the following conditions are met:
87777dab0Sopenharmony_ci//
97777dab0Sopenharmony_ci//   1. Redistributions of source code must retain the above copyright notice,
107777dab0Sopenharmony_ci//      this list of conditions and the following disclaimer.
117777dab0Sopenharmony_ci//
127777dab0Sopenharmony_ci//   2. Redistributions in binary form must reproduce the above copyright
137777dab0Sopenharmony_ci//      notice, this list of conditions and the following disclaimer in the
147777dab0Sopenharmony_ci//      documentation and/or other materials provided with the distribution.
157777dab0Sopenharmony_ci//
167777dab0Sopenharmony_ci//   3. The name of the author may be used to endorse or promote products
177777dab0Sopenharmony_ci//      derived from this software without specific prior written permission.
187777dab0Sopenharmony_ci//
197777dab0Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
207777dab0Sopenharmony_ci// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
217777dab0Sopenharmony_ci// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
227777dab0Sopenharmony_ci// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
237777dab0Sopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
247777dab0Sopenharmony_ci// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
257777dab0Sopenharmony_ci// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
267777dab0Sopenharmony_ci// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
277777dab0Sopenharmony_ci// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
287777dab0Sopenharmony_ci// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
297777dab0Sopenharmony_ci//
307777dab0Sopenharmony_ci///////////////////////////////////////////////////////////////////////////////
317777dab0Sopenharmony_ci
327777dab0Sopenharmony_ci#ifndef _MSC_VER // [
337777dab0Sopenharmony_ci#error "Use this header only with Microsoft Visual C++ compilers!"
347777dab0Sopenharmony_ci#endif // _MSC_VER ]
357777dab0Sopenharmony_ci
367777dab0Sopenharmony_ci#ifndef _MSC_STDINT_H_ // [
377777dab0Sopenharmony_ci#define _MSC_STDINT_H_
387777dab0Sopenharmony_ci
397777dab0Sopenharmony_ci#if _MSC_VER > 1000
407777dab0Sopenharmony_ci#pragma once
417777dab0Sopenharmony_ci#endif
427777dab0Sopenharmony_ci
437777dab0Sopenharmony_ci#include <limits.h>
447777dab0Sopenharmony_ci
457777dab0Sopenharmony_ci// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
467777dab0Sopenharmony_ci// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
477777dab0Sopenharmony_ci// or compiler give many errors like this:
487777dab0Sopenharmony_ci//   error C2733: second C linkage of overloaded function 'wmemchr' not allowed
497777dab0Sopenharmony_ci#ifdef __cplusplus
507777dab0Sopenharmony_ciextern "C" {
517777dab0Sopenharmony_ci#endif
527777dab0Sopenharmony_ci#  include <wchar.h>
537777dab0Sopenharmony_ci#ifdef __cplusplus
547777dab0Sopenharmony_ci}
557777dab0Sopenharmony_ci#endif
567777dab0Sopenharmony_ci
577777dab0Sopenharmony_ci// Define _W64 macros to mark types changing their size, like intptr_t.
587777dab0Sopenharmony_ci#ifndef _W64
597777dab0Sopenharmony_ci#  if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
607777dab0Sopenharmony_ci#     define _W64 __w64
617777dab0Sopenharmony_ci#  else
627777dab0Sopenharmony_ci#     define _W64
637777dab0Sopenharmony_ci#  endif
647777dab0Sopenharmony_ci#endif
657777dab0Sopenharmony_ci
667777dab0Sopenharmony_ci
677777dab0Sopenharmony_ci// 7.18.1 Integer types
687777dab0Sopenharmony_ci
697777dab0Sopenharmony_ci// 7.18.1.1 Exact-width integer types
707777dab0Sopenharmony_ci
717777dab0Sopenharmony_ci// Visual Studio 6 and Embedded Visual C++ 4 doesn't
727777dab0Sopenharmony_ci// realize that, e.g. char has the same size as __int8
737777dab0Sopenharmony_ci// so we give up on __intX for them.
747777dab0Sopenharmony_ci#if (_MSC_VER < 1300)
757777dab0Sopenharmony_ci   typedef signed char       int8_t;
767777dab0Sopenharmony_ci   typedef signed short      int16_t;
777777dab0Sopenharmony_ci   typedef signed int        int32_t;
787777dab0Sopenharmony_ci   typedef unsigned char     uint8_t;
797777dab0Sopenharmony_ci   typedef unsigned short    uint16_t;
807777dab0Sopenharmony_ci   typedef unsigned int      uint32_t;
817777dab0Sopenharmony_ci#else
827777dab0Sopenharmony_ci   typedef signed __int8     int8_t;
837777dab0Sopenharmony_ci   typedef signed __int16    int16_t;
847777dab0Sopenharmony_ci   typedef signed __int32    int32_t;
857777dab0Sopenharmony_ci   typedef unsigned __int8   uint8_t;
867777dab0Sopenharmony_ci   typedef unsigned __int16  uint16_t;
877777dab0Sopenharmony_ci   typedef unsigned __int32  uint32_t;
887777dab0Sopenharmony_ci#endif
897777dab0Sopenharmony_citypedef signed __int64       int64_t;
907777dab0Sopenharmony_citypedef unsigned __int64     uint64_t;
917777dab0Sopenharmony_ci
927777dab0Sopenharmony_ci
937777dab0Sopenharmony_ci// 7.18.1.2 Minimum-width integer types
947777dab0Sopenharmony_citypedef int8_t    int_least8_t;
957777dab0Sopenharmony_citypedef int16_t   int_least16_t;
967777dab0Sopenharmony_citypedef int32_t   int_least32_t;
977777dab0Sopenharmony_citypedef int64_t   int_least64_t;
987777dab0Sopenharmony_citypedef uint8_t   uint_least8_t;
997777dab0Sopenharmony_citypedef uint16_t  uint_least16_t;
1007777dab0Sopenharmony_citypedef uint32_t  uint_least32_t;
1017777dab0Sopenharmony_citypedef uint64_t  uint_least64_t;
1027777dab0Sopenharmony_ci
1037777dab0Sopenharmony_ci// 7.18.1.3 Fastest minimum-width integer types
1047777dab0Sopenharmony_citypedef int8_t    int_fast8_t;
1057777dab0Sopenharmony_citypedef int16_t   int_fast16_t;
1067777dab0Sopenharmony_citypedef int32_t   int_fast32_t;
1077777dab0Sopenharmony_citypedef int64_t   int_fast64_t;
1087777dab0Sopenharmony_citypedef uint8_t   uint_fast8_t;
1097777dab0Sopenharmony_citypedef uint16_t  uint_fast16_t;
1107777dab0Sopenharmony_citypedef uint32_t  uint_fast32_t;
1117777dab0Sopenharmony_citypedef uint64_t  uint_fast64_t;
1127777dab0Sopenharmony_ci
1137777dab0Sopenharmony_ci// 7.18.1.4 Integer types capable of holding object pointers
1147777dab0Sopenharmony_ci#ifdef _WIN64 // [
1157777dab0Sopenharmony_ci   typedef signed __int64    intptr_t;
1167777dab0Sopenharmony_ci   typedef unsigned __int64  uintptr_t;
1177777dab0Sopenharmony_ci#else // _WIN64 ][
1187777dab0Sopenharmony_ci   typedef _W64 signed int   intptr_t;
1197777dab0Sopenharmony_ci   typedef _W64 unsigned int uintptr_t;
1207777dab0Sopenharmony_ci#endif // _WIN64 ]
1217777dab0Sopenharmony_ci
1227777dab0Sopenharmony_ci// 7.18.1.5 Greatest-width integer types
1237777dab0Sopenharmony_citypedef int64_t   intmax_t;
1247777dab0Sopenharmony_citypedef uint64_t  uintmax_t;
1257777dab0Sopenharmony_ci
1267777dab0Sopenharmony_ci
1277777dab0Sopenharmony_ci// 7.18.2 Limits of specified-width integer types
1287777dab0Sopenharmony_ci
1297777dab0Sopenharmony_ci#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [   See footnote 220 at page 257 and footnote 221 at page 259
1307777dab0Sopenharmony_ci
1317777dab0Sopenharmony_ci// 7.18.2.1 Limits of exact-width integer types
1327777dab0Sopenharmony_ci#define INT8_MIN     ((int8_t)_I8_MIN)
1337777dab0Sopenharmony_ci#define INT8_MAX     _I8_MAX
1347777dab0Sopenharmony_ci#define INT16_MIN    ((int16_t)_I16_MIN)
1357777dab0Sopenharmony_ci#define INT16_MAX    _I16_MAX
1367777dab0Sopenharmony_ci#define INT32_MIN    ((int32_t)_I32_MIN)
1377777dab0Sopenharmony_ci#define INT32_MAX    _I32_MAX
1387777dab0Sopenharmony_ci#define INT64_MIN    ((int64_t)_I64_MIN)
1397777dab0Sopenharmony_ci#define INT64_MAX    _I64_MAX
1407777dab0Sopenharmony_ci#define UINT8_MAX    _UI8_MAX
1417777dab0Sopenharmony_ci#define UINT16_MAX   _UI16_MAX
1427777dab0Sopenharmony_ci#define UINT32_MAX   _UI32_MAX
1437777dab0Sopenharmony_ci#define UINT64_MAX   _UI64_MAX
1447777dab0Sopenharmony_ci
1457777dab0Sopenharmony_ci// 7.18.2.2 Limits of minimum-width integer types
1467777dab0Sopenharmony_ci#define INT_LEAST8_MIN    INT8_MIN
1477777dab0Sopenharmony_ci#define INT_LEAST8_MAX    INT8_MAX
1487777dab0Sopenharmony_ci#define INT_LEAST16_MIN   INT16_MIN
1497777dab0Sopenharmony_ci#define INT_LEAST16_MAX   INT16_MAX
1507777dab0Sopenharmony_ci#define INT_LEAST32_MIN   INT32_MIN
1517777dab0Sopenharmony_ci#define INT_LEAST32_MAX   INT32_MAX
1527777dab0Sopenharmony_ci#define INT_LEAST64_MIN   INT64_MIN
1537777dab0Sopenharmony_ci#define INT_LEAST64_MAX   INT64_MAX
1547777dab0Sopenharmony_ci#define UINT_LEAST8_MAX   UINT8_MAX
1557777dab0Sopenharmony_ci#define UINT_LEAST16_MAX  UINT16_MAX
1567777dab0Sopenharmony_ci#define UINT_LEAST32_MAX  UINT32_MAX
1577777dab0Sopenharmony_ci#define UINT_LEAST64_MAX  UINT64_MAX
1587777dab0Sopenharmony_ci
1597777dab0Sopenharmony_ci// 7.18.2.3 Limits of fastest minimum-width integer types
1607777dab0Sopenharmony_ci#define INT_FAST8_MIN    INT8_MIN
1617777dab0Sopenharmony_ci#define INT_FAST8_MAX    INT8_MAX
1627777dab0Sopenharmony_ci#define INT_FAST16_MIN   INT16_MIN
1637777dab0Sopenharmony_ci#define INT_FAST16_MAX   INT16_MAX
1647777dab0Sopenharmony_ci#define INT_FAST32_MIN   INT32_MIN
1657777dab0Sopenharmony_ci#define INT_FAST32_MAX   INT32_MAX
1667777dab0Sopenharmony_ci#define INT_FAST64_MIN   INT64_MIN
1677777dab0Sopenharmony_ci#define INT_FAST64_MAX   INT64_MAX
1687777dab0Sopenharmony_ci#define UINT_FAST8_MAX   UINT8_MAX
1697777dab0Sopenharmony_ci#define UINT_FAST16_MAX  UINT16_MAX
1707777dab0Sopenharmony_ci#define UINT_FAST32_MAX  UINT32_MAX
1717777dab0Sopenharmony_ci#define UINT_FAST64_MAX  UINT64_MAX
1727777dab0Sopenharmony_ci
1737777dab0Sopenharmony_ci// 7.18.2.4 Limits of integer types capable of holding object pointers
1747777dab0Sopenharmony_ci#ifdef _WIN64 // [
1757777dab0Sopenharmony_ci#  define INTPTR_MIN   INT64_MIN
1767777dab0Sopenharmony_ci#  define INTPTR_MAX   INT64_MAX
1777777dab0Sopenharmony_ci#  define UINTPTR_MAX  UINT64_MAX
1787777dab0Sopenharmony_ci#else // _WIN64 ][
1797777dab0Sopenharmony_ci#  define INTPTR_MIN   INT32_MIN
1807777dab0Sopenharmony_ci#  define INTPTR_MAX   INT32_MAX
1817777dab0Sopenharmony_ci#  define UINTPTR_MAX  UINT32_MAX
1827777dab0Sopenharmony_ci#endif // _WIN64 ]
1837777dab0Sopenharmony_ci
1847777dab0Sopenharmony_ci// 7.18.2.5 Limits of greatest-width integer types
1857777dab0Sopenharmony_ci#define INTMAX_MIN   INT64_MIN
1867777dab0Sopenharmony_ci#define INTMAX_MAX   INT64_MAX
1877777dab0Sopenharmony_ci#define UINTMAX_MAX  UINT64_MAX
1887777dab0Sopenharmony_ci
1897777dab0Sopenharmony_ci// 7.18.3 Limits of other integer types
1907777dab0Sopenharmony_ci
1917777dab0Sopenharmony_ci#ifdef _WIN64 // [
1927777dab0Sopenharmony_ci#  define PTRDIFF_MIN  _I64_MIN
1937777dab0Sopenharmony_ci#  define PTRDIFF_MAX  _I64_MAX
1947777dab0Sopenharmony_ci#else  // _WIN64 ][
1957777dab0Sopenharmony_ci#  define PTRDIFF_MIN  _I32_MIN
1967777dab0Sopenharmony_ci#  define PTRDIFF_MAX  _I32_MAX
1977777dab0Sopenharmony_ci#endif  // _WIN64 ]
1987777dab0Sopenharmony_ci
1997777dab0Sopenharmony_ci#define SIG_ATOMIC_MIN  INT_MIN
2007777dab0Sopenharmony_ci#define SIG_ATOMIC_MAX  INT_MAX
2017777dab0Sopenharmony_ci
2027777dab0Sopenharmony_ci#ifndef SIZE_MAX // [
2037777dab0Sopenharmony_ci#  ifdef _WIN64 // [
2047777dab0Sopenharmony_ci#     define SIZE_MAX  _UI64_MAX
2057777dab0Sopenharmony_ci#  else // _WIN64 ][
2067777dab0Sopenharmony_ci#     define SIZE_MAX  _UI32_MAX
2077777dab0Sopenharmony_ci#  endif // _WIN64 ]
2087777dab0Sopenharmony_ci#endif // SIZE_MAX ]
2097777dab0Sopenharmony_ci
2107777dab0Sopenharmony_ci// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
2117777dab0Sopenharmony_ci#ifndef WCHAR_MIN // [
2127777dab0Sopenharmony_ci#  define WCHAR_MIN  0
2137777dab0Sopenharmony_ci#endif  // WCHAR_MIN ]
2147777dab0Sopenharmony_ci#ifndef WCHAR_MAX // [
2157777dab0Sopenharmony_ci#  define WCHAR_MAX  _UI16_MAX
2167777dab0Sopenharmony_ci#endif  // WCHAR_MAX ]
2177777dab0Sopenharmony_ci
2187777dab0Sopenharmony_ci#define WINT_MIN  0
2197777dab0Sopenharmony_ci#define WINT_MAX  _UI16_MAX
2207777dab0Sopenharmony_ci
2217777dab0Sopenharmony_ci#endif // __STDC_LIMIT_MACROS ]
2227777dab0Sopenharmony_ci
2237777dab0Sopenharmony_ci
2247777dab0Sopenharmony_ci// 7.18.4 Limits of other integer types
2257777dab0Sopenharmony_ci
2267777dab0Sopenharmony_ci#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [   See footnote 224 at page 260
2277777dab0Sopenharmony_ci
2287777dab0Sopenharmony_ci// 7.18.4.1 Macros for minimum-width integer constants
2297777dab0Sopenharmony_ci
2307777dab0Sopenharmony_ci#define INT8_C(val)  val##i8
2317777dab0Sopenharmony_ci#define INT16_C(val) val##i16
2327777dab0Sopenharmony_ci#define INT32_C(val) val##i32
2337777dab0Sopenharmony_ci#define INT64_C(val) val##i64
2347777dab0Sopenharmony_ci
2357777dab0Sopenharmony_ci#define UINT8_C(val)  val##ui8
2367777dab0Sopenharmony_ci#define UINT16_C(val) val##ui16
2377777dab0Sopenharmony_ci#define UINT32_C(val) val##ui32
2387777dab0Sopenharmony_ci#define UINT64_C(val) val##ui64
2397777dab0Sopenharmony_ci
2407777dab0Sopenharmony_ci// 7.18.4.2 Macros for greatest-width integer constants
2417777dab0Sopenharmony_ci#define INTMAX_C   INT64_C
2427777dab0Sopenharmony_ci#define UINTMAX_C  UINT64_C
2437777dab0Sopenharmony_ci
2447777dab0Sopenharmony_ci#endif // __STDC_CONSTANT_MACROS ]
2457777dab0Sopenharmony_ci
2467777dab0Sopenharmony_ci
2477777dab0Sopenharmony_ci#endif // _MSC_STDINT_H_ ]
248