xref: /PHP-7.4/win32/php_stdint.h (revision 92ac598a)
11e820ecaSPierre Joye // ISO C9x  compliant stdint.h for Microsoft Visual Studio
2*b7a7b1a6SStanislav Malyshev // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
3*b7a7b1a6SStanislav Malyshev //
408659c2dSSebastian Bergmann //  Copyright (c) 2006-2009 Alexander Chemeris
5*b7a7b1a6SStanislav Malyshev //
61e820ecaSPierre Joye // Redistribution and use in source and binary forms, with or without
71e820ecaSPierre Joye // modification, are permitted provided that the following conditions are met:
8*b7a7b1a6SStanislav Malyshev //
91e820ecaSPierre Joye //   1. Redistributions of source code must retain the above copyright notice,
101e820ecaSPierre Joye //      this list of conditions and the following disclaimer.
11*b7a7b1a6SStanislav Malyshev //
121e820ecaSPierre Joye //   2. Redistributions in binary form must reproduce the above copyright
131e820ecaSPierre Joye //      notice, this list of conditions and the following disclaimer in the
141e820ecaSPierre Joye //      documentation and/or other materials provided with the distribution.
15*b7a7b1a6SStanislav Malyshev //
161e820ecaSPierre Joye //   3. The name of the author may be used to endorse or promote products
171e820ecaSPierre Joye //      derived from this software without specific prior written permission.
18*b7a7b1a6SStanislav Malyshev //
191e820ecaSPierre Joye // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
201e820ecaSPierre Joye // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
211e820ecaSPierre Joye // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
221e820ecaSPierre Joye // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
231e820ecaSPierre Joye // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
241e820ecaSPierre Joye // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25*b7a7b1a6SStanislav Malyshev // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
261e820ecaSPierre Joye // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
271e820ecaSPierre Joye // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
281e820ecaSPierre Joye // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*b7a7b1a6SStanislav Malyshev //
301e820ecaSPierre Joye ///////////////////////////////////////////////////////////////////////////////
311e820ecaSPierre Joye 
321e820ecaSPierre Joye #ifndef _MSC_VER // [
331e820ecaSPierre Joye #error "Use this header only with Microsoft Visual C++ compilers!"
341e820ecaSPierre Joye #endif // _MSC_VER ]
351e820ecaSPierre Joye 
36bea7d06bSAnatol Belski // Starting with vc14, many of the C11 features are now included, so we only
376b0eca06SChris Tankersley // need many of these typedefs and defines for older VS suites
386b0eca06SChris Tankersley #if _MSC_VER < 1900
396b0eca06SChris Tankersley 
401e820ecaSPierre Joye #ifndef _MSC_STDINT_H_ // [
411e820ecaSPierre Joye #define _MSC_STDINT_H_
421e820ecaSPierre Joye 
43713e9a7eSAnatol Belski #ifndef _STDINT
44713e9a7eSAnatol Belski # define _STDINT
45713e9a7eSAnatol Belski #endif
46713e9a7eSAnatol Belski 
471e820ecaSPierre Joye #if _MSC_VER > 1000
481e820ecaSPierre Joye #pragma once
491e820ecaSPierre Joye #endif
501e820ecaSPierre Joye 
511e820ecaSPierre Joye #include <limits.h>
521e820ecaSPierre Joye 
531e820ecaSPierre Joye // For Visual Studio 6 in C++ mode wrap <wchar.h> include with 'extern "C++" {}'
541e820ecaSPierre Joye // or compiler give many errors like this:
551e820ecaSPierre Joye //   error C2733: second C linkage of overloaded function 'wmemchr' not allowed
561e820ecaSPierre Joye #if (_MSC_VER < 1300) && defined(__cplusplus)
571e820ecaSPierre Joye    extern "C++" {
58*b7a7b1a6SStanislav Malyshev #endif
591e820ecaSPierre Joye #     include <wchar.h>
601e820ecaSPierre Joye #if (_MSC_VER < 1300) && defined(__cplusplus)
611e820ecaSPierre Joye    }
621e820ecaSPierre Joye #endif
631e820ecaSPierre Joye 
641e820ecaSPierre Joye // Define _W64 macros to mark types changing their size, like intptr_t.
651e820ecaSPierre Joye #ifndef _W64
661e820ecaSPierre Joye #  if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
671e820ecaSPierre Joye #     define _W64 __w64
681e820ecaSPierre Joye #  else
691e820ecaSPierre Joye #     define _W64
701e820ecaSPierre Joye #  endif
711e820ecaSPierre Joye #endif
721e820ecaSPierre Joye 
731e820ecaSPierre Joye 
741e820ecaSPierre Joye // 7.18.1 Integer types
751e820ecaSPierre Joye 
761e820ecaSPierre Joye // 7.18.1.1 Exact-width integer types
777189039dSAnatol Belski #ifndef int8_t
781e820ecaSPierre Joye typedef __int8            int8_t;
797189039dSAnatol Belski #endif
807189039dSAnatol Belski #ifndef int16_t
811e820ecaSPierre Joye typedef __int16           int16_t;
827189039dSAnatol Belski #endif
83a5af8a7eSPierre Joye #ifndef int32_t
841e820ecaSPierre Joye typedef __int32           int32_t;
85a5af8a7eSPierre Joye #endif
86a5af8a7eSPierre Joye #ifndef int64_t
871e820ecaSPierre Joye typedef __int64           int64_t;
88a5af8a7eSPierre Joye #endif
89a5af8a7eSPierre Joye #ifndef uint8_t
901e820ecaSPierre Joye typedef unsigned __int8   uint8_t;
91a5af8a7eSPierre Joye #endif
921e820ecaSPierre Joye typedef unsigned __int16  uint16_t;
93a5af8a7eSPierre Joye #ifndef uint32_t
941e820ecaSPierre Joye typedef unsigned __int32  uint32_t;
95a5af8a7eSPierre Joye #endif
961e820ecaSPierre Joye typedef unsigned __int64  uint64_t;
971e820ecaSPierre Joye 
981e820ecaSPierre Joye // 7.18.1.2 Minimum-width integer types
991e820ecaSPierre Joye typedef int8_t    int_least8_t;
1001e820ecaSPierre Joye typedef int16_t   int_least16_t;
1011e820ecaSPierre Joye typedef int32_t   int_least32_t;
1021e820ecaSPierre Joye typedef int64_t   int_least64_t;
1031e820ecaSPierre Joye typedef uint8_t   uint_least8_t;
1041e820ecaSPierre Joye typedef uint16_t  uint_least16_t;
1051e820ecaSPierre Joye typedef uint32_t  uint_least32_t;
1061e820ecaSPierre Joye typedef uint64_t  uint_least64_t;
1071e820ecaSPierre Joye 
1081e820ecaSPierre Joye // 7.18.1.3 Fastest minimum-width integer types
1091e820ecaSPierre Joye typedef int8_t    int_fast8_t;
1101e820ecaSPierre Joye typedef int16_t   int_fast16_t;
1111e820ecaSPierre Joye typedef int32_t   int_fast32_t;
1121e820ecaSPierre Joye typedef int64_t   int_fast64_t;
1131e820ecaSPierre Joye typedef uint8_t   uint_fast8_t;
1141e820ecaSPierre Joye typedef uint16_t  uint_fast16_t;
1151e820ecaSPierre Joye typedef uint32_t  uint_fast32_t;
1161e820ecaSPierre Joye typedef uint32_t  u_int32_t;
1171e820ecaSPierre Joye typedef uint64_t  uint_fast64_t;
1181e820ecaSPierre Joye 
1191e820ecaSPierre Joye // 7.18.1.4 Integer types capable of holding object pointers
1201c252d5dSAnatol Belski /* intptr_t and uintptr_t are available from stddef.h */
1211c252d5dSAnatol Belski #include <stddef.h>
1221e820ecaSPierre Joye 
1231e820ecaSPierre Joye // 7.18.1.5 Greatest-width integer types
1241e820ecaSPierre Joye typedef int64_t   intmax_t;
1251e820ecaSPierre Joye typedef uint64_t  uintmax_t;
1261e820ecaSPierre Joye 
1271e820ecaSPierre Joye 
1281e820ecaSPierre Joye // 7.18.2 Limits of specified-width integer types
1291e820ecaSPierre Joye 
1301e820ecaSPierre Joye #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [   See footnote 220 at page 257 and footnote 221 at page 259
1311e820ecaSPierre Joye 
1321e820ecaSPierre Joye // 7.18.2.1 Limits of exact-width integer types
1338ee2a4a9SAnatol Belski #if _MSC_VER >= 1700 && !defined(_INTSAFE_H_INCLUDED_)
1341e820ecaSPierre Joye #define INT8_MIN     ((int8_t)_I8_MIN)
1351e820ecaSPierre Joye #define INT8_MAX     _I8_MAX
1361e820ecaSPierre Joye #define INT16_MIN    ((int16_t)_I16_MIN)
1371e820ecaSPierre Joye #define INT16_MAX    _I16_MAX
1381e820ecaSPierre Joye #define INT32_MIN    ((int32_t)_I32_MIN)
1391e820ecaSPierre Joye #define INT32_MAX    _I32_MAX
1401e820ecaSPierre Joye #define INT64_MIN    ((int64_t)_I64_MIN)
1411e820ecaSPierre Joye #define INT64_MAX    _I64_MAX
1421e820ecaSPierre Joye #define UINT8_MAX    _UI8_MAX
1431e820ecaSPierre Joye #define UINT16_MAX   _UI16_MAX
1441e820ecaSPierre Joye #define UINT32_MAX   _UI32_MAX
1451e820ecaSPierre Joye #define UINT64_MAX   _UI64_MAX
1468ee2a4a9SAnatol Belski #endif
1471e820ecaSPierre Joye 
1481e820ecaSPierre Joye // 7.18.2.2 Limits of minimum-width integer types
1491e820ecaSPierre Joye #define INT_LEAST8_MIN    INT8_MIN
1501e820ecaSPierre Joye #define INT_LEAST8_MAX    INT8_MAX
1511e820ecaSPierre Joye #define INT_LEAST16_MIN   INT16_MIN
1521e820ecaSPierre Joye #define INT_LEAST16_MAX   INT16_MAX
1531e820ecaSPierre Joye #define INT_LEAST32_MIN   INT32_MIN
1541e820ecaSPierre Joye #define INT_LEAST32_MAX   INT32_MAX
1551e820ecaSPierre Joye #define INT_LEAST64_MIN   INT64_MIN
1561e820ecaSPierre Joye #define INT_LEAST64_MAX   INT64_MAX
1571e820ecaSPierre Joye #define UINT_LEAST8_MAX   UINT8_MAX
1581e820ecaSPierre Joye #define UINT_LEAST16_MAX  UINT16_MAX
1591e820ecaSPierre Joye #define UINT_LEAST32_MAX  UINT32_MAX
1601e820ecaSPierre Joye #define UINT_LEAST64_MAX  UINT64_MAX
1611e820ecaSPierre Joye 
1621e820ecaSPierre Joye // 7.18.2.3 Limits of fastest minimum-width integer types
1631e820ecaSPierre Joye #define INT_FAST8_MIN    INT8_MIN
1641e820ecaSPierre Joye #define INT_FAST8_MAX    INT8_MAX
1651e820ecaSPierre Joye #define INT_FAST16_MIN   INT16_MIN
1661e820ecaSPierre Joye #define INT_FAST16_MAX   INT16_MAX
1671e820ecaSPierre Joye #define INT_FAST32_MIN   INT32_MIN
1681e820ecaSPierre Joye #define INT_FAST32_MAX   INT32_MAX
1691e820ecaSPierre Joye #define INT_FAST64_MIN   INT64_MIN
1701e820ecaSPierre Joye #define INT_FAST64_MAX   INT64_MAX
1711e820ecaSPierre Joye #define UINT_FAST8_MAX   UINT8_MAX
1721e820ecaSPierre Joye #define UINT_FAST16_MAX  UINT16_MAX
1731e820ecaSPierre Joye #define UINT_FAST32_MAX  UINT32_MAX
1741e820ecaSPierre Joye #define UINT_FAST64_MAX  UINT64_MAX
1751e820ecaSPierre Joye 
1761e820ecaSPierre Joye // 7.18.2.4 Limits of integer types capable of holding object pointers
1771e820ecaSPierre Joye #ifdef _WIN64 // [
1781e820ecaSPierre Joye #  define INTPTR_MIN   INT64_MIN
1791e820ecaSPierre Joye #  define INTPTR_MAX   INT64_MAX
1801e820ecaSPierre Joye #  define UINTPTR_MAX  UINT64_MAX
1811e820ecaSPierre Joye #else // _WIN64 ][
1821e820ecaSPierre Joye #  define INTPTR_MIN   INT32_MIN
1831e820ecaSPierre Joye #  define INTPTR_MAX   INT32_MAX
1841e820ecaSPierre Joye #  define UINTPTR_MAX  UINT32_MAX
1851e820ecaSPierre Joye #endif // _WIN64 ]
1861e820ecaSPierre Joye 
1871e820ecaSPierre Joye // 7.18.2.5 Limits of greatest-width integer types
1881e820ecaSPierre Joye #define INTMAX_MIN   INT64_MIN
1891e820ecaSPierre Joye #define INTMAX_MAX   INT64_MAX
1901e820ecaSPierre Joye #define UINTMAX_MAX  UINT64_MAX
1911e820ecaSPierre Joye 
1921e820ecaSPierre Joye // 7.18.3 Limits of other integer types
1931e820ecaSPierre Joye 
1941e820ecaSPierre Joye #ifdef _WIN64 // [
1951e820ecaSPierre Joye #  define PTRDIFF_MIN  _I64_MIN
1961e820ecaSPierre Joye #  define PTRDIFF_MAX  _I64_MAX
1971e820ecaSPierre Joye #else  // _WIN64 ][
1981e820ecaSPierre Joye #  define PTRDIFF_MIN  _I32_MIN
1991e820ecaSPierre Joye #  define PTRDIFF_MAX  _I32_MAX
2001e820ecaSPierre Joye #endif  // _WIN64 ]
2011e820ecaSPierre Joye 
2021e820ecaSPierre Joye #define SIG_ATOMIC_MIN  INT_MIN
2031e820ecaSPierre Joye #define SIG_ATOMIC_MAX  INT_MAX
2041e820ecaSPierre Joye 
2051e820ecaSPierre Joye #ifndef SIZE_MAX // [
2061e820ecaSPierre Joye #  ifdef _WIN64 // [
2071e820ecaSPierre Joye #     define SIZE_MAX  _UI64_MAX
2081e820ecaSPierre Joye #  else // _WIN64 ][
2091e820ecaSPierre Joye #     define SIZE_MAX  _UI32_MAX
2101e820ecaSPierre Joye #  endif // _WIN64 ]
2111e820ecaSPierre Joye #endif // SIZE_MAX ]
2121e820ecaSPierre Joye 
2131e820ecaSPierre Joye // WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
2141e820ecaSPierre Joye #ifndef WCHAR_MIN // [
2151e820ecaSPierre Joye #  define WCHAR_MIN  0
2161e820ecaSPierre Joye #endif  // WCHAR_MIN ]
2171e820ecaSPierre Joye #ifndef WCHAR_MAX // [
2181e820ecaSPierre Joye #  define WCHAR_MAX  _UI16_MAX
2191e820ecaSPierre Joye #endif  // WCHAR_MAX ]
2201e820ecaSPierre Joye 
2211e820ecaSPierre Joye #define WINT_MIN  0
2221e820ecaSPierre Joye #define WINT_MAX  _UI16_MAX
2231e820ecaSPierre Joye 
2241e820ecaSPierre Joye #endif // __STDC_LIMIT_MACROS ]
2251e820ecaSPierre Joye 
2261e820ecaSPierre Joye 
2271e820ecaSPierre Joye // 7.18.4 Limits of other integer types
2281e820ecaSPierre Joye 
2291e820ecaSPierre Joye #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [   See footnote 224 at page 260
2301e820ecaSPierre Joye 
2311e820ecaSPierre Joye // 7.18.4.1 Macros for minimum-width integer constants
2321e820ecaSPierre Joye 
2331e820ecaSPierre Joye #define INT8_C(val)  val##i8
2341e820ecaSPierre Joye #define INT16_C(val) val##i16
2351e820ecaSPierre Joye #define INT32_C(val) val##i32
2361e820ecaSPierre Joye #define INT64_C(val) val##i64
2371e820ecaSPierre Joye 
2381e820ecaSPierre Joye #define UINT8_C(val)  val##ui8
2391e820ecaSPierre Joye #define UINT16_C(val) val##ui16
2401e820ecaSPierre Joye #define UINT32_C(val) val##ui32
2411e820ecaSPierre Joye #define UINT64_C(val) val##ui64
2421e820ecaSPierre Joye 
2431e820ecaSPierre Joye // 7.18.4.2 Macros for greatest-width integer constants
2441e820ecaSPierre Joye #define INTMAX_C   INT64_C
2451e820ecaSPierre Joye #define UINTMAX_C  UINT64_C
2461e820ecaSPierre Joye 
2471063c834SKalle Sommer Nielsen #if _MSC_VER < 1600
llabs(int64_t i)2481063c834SKalle Sommer Nielsen static __inline int64_t llabs(int64_t i)
2491063c834SKalle Sommer Nielsen {
2501063c834SKalle Sommer Nielsen 	return i >= 0 ? i: -i;
2511063c834SKalle Sommer Nielsen }
2521063c834SKalle Sommer Nielsen #endif
253ffca50caSPierre Joye 
2541e820ecaSPierre Joye #endif // __STDC_CONSTANT_MACROS ]
2551e820ecaSPierre Joye 
2561e820ecaSPierre Joye 
2571e820ecaSPierre Joye #endif // _MSC_STDINT_H_ ]
2586b0eca06SChris Tankersley 
2596b0eca06SChris Tankersley #else
2606b0eca06SChris Tankersley #include <stdint.h>
2616b0eca06SChris Tankersley #endif
2626b0eca06SChris Tankersley 
2636b0eca06SChris Tankersley #ifndef u_char
2646b0eca06SChris Tankersley typedef unsigned __int8   u_char;
2656b0eca06SChris Tankersley #endif
266