diff --git a/include/inttypes.h b/include/inttypes.h index 17563562..1c894c4a 100644 --- a/include/inttypes.h +++ b/include/inttypes.h @@ -1,45 +1,97 @@ -#pragma once - -#include - -#define PRId8 "%hhd" -#define PRId16 "%hd" -#define PRId32 "%d" -#define PRId64 "%ld" -#define PRIdMAX "%zd" -#define PRIdPTR "%zd" - -#define PRIi8 "%hhi" -#define PRIi16 "%hi" -#define PRIi32 "%i" -#define PRIi64 "%li" -#define PRIiMAX "%zi" -#define PRIiPTR "%zi" - -#define PRIu8 "%hhu" -#define PRIu16 "%hu" -#define PRIu32 "%u" -#define PRIu64 "%lu" -#define PRIuMAX "%zu" -#define PRIuPTR "%zu" - -#define PRIx8 "%hhx" -#define PRIx16 "%hx" -#define PRIx32 "%x" -#define PRIx64 "%lx" -#define PRIxMAX "%zx" -#define PRIxPTR "%zx" - -#define PRIX8 "%hhX" -#define PRIX16 "%hX" -#define PRIX32 "%X" -#define PRIX64 "%lX" -#define PRIXMAX "%zX" -#define PRIXPTR "%zX" - -#define PRIo8 "%hho" -#define PRIo16 "%ho" -#define PRIo32 "%o" -#define PRIo64 "%lo" -#define PRIoMAX "%zo" -#define PRIoPTR "%zo" +/*===---- inttypes.h - Standard header for integer printf macros ----------===*\ + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * +\*===----------------------------------------------------------------------===*/ + +#ifndef __CLANG_INTTYPES_H +// AIX system headers need inttypes.h to be re-enterable while _STD_TYPES_T +// is defined until an inclusion of it without _STD_TYPES_T occurs, in which +// case the header guard macro is defined. +#if !defined(_AIX) || !defined(_STD_TYPES_T) +#define __CLANG_INTTYPES_H +#endif + +#if defined(_MSC_VER) && _MSC_VER < 1800 +#error MSVC does not have inttypes.h prior to Visual Studio 2013 +#endif + +#include_next + +#if defined(_MSC_VER) && _MSC_VER < 1900 +/* MSVC headers define int32_t as int, but PRIx32 as "lx" instead of "x". + * This triggers format warnings, so fix it up here. */ +#undef PRId32 +#undef PRIdLEAST32 +#undef PRIdFAST32 +#undef PRIi32 +#undef PRIiLEAST32 +#undef PRIiFAST32 +#undef PRIo32 +#undef PRIoLEAST32 +#undef PRIoFAST32 +#undef PRIu32 +#undef PRIuLEAST32 +#undef PRIuFAST32 +#undef PRIx32 +#undef PRIxLEAST32 +#undef PRIxFAST32 +#undef PRIX32 +#undef PRIXLEAST32 +#undef PRIXFAST32 + +#undef SCNd32 +#undef SCNdLEAST32 +#undef SCNdFAST32 +#undef SCNi32 +#undef SCNiLEAST32 +#undef SCNiFAST32 +#undef SCNo32 +#undef SCNoLEAST32 +#undef SCNoFAST32 +#undef SCNu32 +#undef SCNuLEAST32 +#undef SCNuFAST32 +#undef SCNx32 +#undef SCNxLEAST32 +#undef SCNxFAST32 + +#define PRId32 "d" +#define PRIdLEAST32 "d" +#define PRIdFAST32 "d" +#define PRIi32 "i" +#define PRIiLEAST32 "i" +#define PRIiFAST32 "i" +#define PRIo32 "o" +#define PRIoLEAST32 "o" +#define PRIoFAST32 "o" +#define PRIu32 "u" +#define PRIuLEAST32 "u" +#define PRIuFAST32 "u" +#define PRIx32 "x" +#define PRIxLEAST32 "x" +#define PRIxFAST32 "x" +#define PRIX32 "X" +#define PRIXLEAST32 "X" +#define PRIXFAST32 "X" + +#define SCNd32 "d" +#define SCNdLEAST32 "d" +#define SCNdFAST32 "d" +#define SCNi32 "i" +#define SCNiLEAST32 "i" +#define SCNiFAST32 "i" +#define SCNo32 "o" +#define SCNoLEAST32 "o" +#define SCNoFAST32 "o" +#define SCNu32 "u" +#define SCNuLEAST32 "u" +#define SCNuFAST32 "u" +#define SCNx32 "x" +#define SCNxLEAST32 "x" +#define SCNxFAST32 "x" +#endif + +#endif /* __CLANG_INTTYPES_H */ diff --git a/include/stdint.h b/include/stdint.h index 6d65cb56..ec7f949a 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -1,495 +1,930 @@ -#pragma once - -/* - * Copyright (c) 2004, 2005 by - * Ralf Corsepius, Ulm/Germany. All rights reserved. +/*===---- stdint.h - Standard header for sized integer types --------------===*\ * - * Permission to use, copy, modify, and distribute this software - * is freely granted, provided that this notice is preserved. - */ - -#ifndef _STDINT_H -#define _STDINT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(__GNUC__) \ - && ((__GNUC__ >= 4) \ - || ((__GNUC__ >= 3) && defined(__GNUC_MINOR__) \ - && (__GNUC_MINOR__ > 2))) -/* gcc > 3.2 implicitly defines the values we are interested */ -#define __STDINT_EXP(x) __##x##__ -#else -#define __STDINT_EXP(x) x -#include -#endif - -/* Check if "long long" is 64bit wide */ -/* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */ -#if (defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff)) \ - || (defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff)) -#define __have_longlong64 1 -#endif - -/* Check if "long" is 64bit or 32bit wide */ -#if __STDINT_EXP(LONG_MAX) > 0x7fffffff -#define __have_long64 1 -#elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) -#define __have_long32 1 -#endif - -#if __STDINT_EXP(SCHAR_MAX) == 0x7f -typedef signed char int8_t; -typedef unsigned char uint8_t; -#define __int8_t_defined 1 -#endif - -#if __int8_t_defined -typedef signed char int_least8_t; -typedef unsigned char uint_least8_t; -#define __int_least8_t_defined 1 -#endif - -#if __STDINT_EXP(SHRT_MAX) == 0x7fff -typedef signed short int16_t; -typedef unsigned short uint16_t; -#define __int16_t_defined 1 -#elif __STDINT_EXP(INT_MAX) == 0x7fff -typedef signed int int16_t; -typedef unsigned int uint16_t; -#define __int16_t_defined 1 -#elif __STDINT_EXP(SCHAR_MAX) == 0x7fff -typedef signed char int16_t; -typedef unsigned char uint16_t; -#define __int16_t_defined 1 -#endif - -#if __int16_t_defined -typedef int16_t int_least16_t; -typedef uint16_t uint_least16_t; -#define __int_least16_t_defined 1 - -#if !__int_least8_t_defined -typedef int16_t int_least8_t; -typedef uint16_t uint_least8_t; -#define __int_least8_t_defined 1 -#endif -#endif - -#if __have_long32 -typedef signed long int32_t; -typedef unsigned long uint32_t; -#define __int32_t_defined 1 -#elif __STDINT_EXP(INT_MAX) == 0x7fffffffL -typedef signed int int32_t; -typedef unsigned int uint32_t; -#define __int32_t_defined 1 -#elif __STDINT_EXP(SHRT_MAX) == 0x7fffffffL -typedef signed short int32_t; -typedef unsigned short uint32_t; -#define __int32_t_defined 1 -#elif __STDINT_EXP(SCHAR_MAX) == 0x7fffffffL -typedef signed char int32_t; -typedef unsigned char uint32_t; -#define __int32_t_defined 1 -#endif - -#if __int32_t_defined -typedef int32_t int_least32_t; -typedef uint32_t uint_least32_t; -#define __int_least32_t_defined 1 + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * +\*===----------------------------------------------------------------------===*/ -#if !__int_least8_t_defined -typedef int32_t int_least8_t; -typedef uint32_t uint_least8_t; -#define __int_least8_t_defined 1 +#ifndef __CLANG_STDINT_H +// AIX system headers need stdint.h to be re-enterable while _STD_TYPES_T +// is defined until an inclusion of it without _STD_TYPES_T occurs, in which +// case the header guard macro is defined. +#if !defined(_AIX) || !defined(_STD_TYPES_T) || !defined(__STDC_HOSTED__) +#define __CLANG_STDINT_H #endif -#if !__int_least16_t_defined -typedef int32_t int_least16_t; -typedef uint32_t uint_least16_t; -#define __int_least16_t_defined 1 +/* If we're hosted, fall back to the system's stdint.h, which might have + * additional definitions. + */ +#if __STDC_HOSTED__ && __has_include_next() + +// C99 7.18.3 Limits of other integer types +// +// Footnote 219, 220: C++ implementations should define these macros only when +// __STDC_LIMIT_MACROS is defined before is included. +// +// Footnote 222: C++ implementations should define these macros only when +// __STDC_CONSTANT_MACROS is defined before is included. +// +// C++11 [cstdint.syn]p2: +// +// The macros defined by are provided unconditionally. In particular, +// the symbols __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS (mentioned in +// footnotes 219, 220, and 222 in the C standard) play no role in C++. +// +// C11 removed the problematic footnotes. +// +// Work around this inconsistency by always defining those macros in C++ mode, +// so that a C library implementation which follows the C99 standard can be +// used in C++. +#ifdef __cplusplus +#if !defined(__STDC_LIMIT_MACROS) +#define __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS_DEFINED_BY_CLANG #endif +#if !defined(__STDC_CONSTANT_MACROS) +#define __STDC_CONSTANT_MACROS +#define __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG #endif - -#if __have_long64 -typedef signed long int64_t; -typedef unsigned long uint64_t; -#define __int64_t_defined 1 -#elif __have_longlong64 -typedef signed long long int64_t; -typedef unsigned long long uint64_t; -#define __int64_t_defined 1 -#elif __STDINT_EXP(INT_MAX) > 0x7fffffff -typedef signed int int64_t; -typedef unsigned int uint64_t; -#define __int64_t_defined 1 #endif -#if __int64_t_defined -typedef int64_t int_least64_t; -typedef uint64_t uint_least64_t; -#define __int_least64_t_defined 1 +#include_next -#if !__int_least8_t_defined -typedef int64_t int_least8_t; -typedef uint64_t uint_least8_t; -#define __int_least8_t_defined 1 +#ifdef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG +#undef __STDC_LIMIT_MACROS +#undef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG #endif - -#if !__int_least16_t_defined -typedef int64_t int_least16_t; -typedef uint64_t uint_least16_t; -#define __int_least16_t_defined 1 +#ifdef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG +#undef __STDC_CONSTANT_MACROS +#undef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG #endif -#if !__int_least32_t_defined -typedef int64_t int_least32_t; -typedef uint64_t uint_least32_t; -#define __int_least32_t_defined 1 -#endif -#endif +#else -/* - * Fastest minimum-width integer types +/* C99 7.18.1.1 Exact-width integer types. + * C99 7.18.1.2 Minimum-width integer types. + * C99 7.18.1.3 Fastest minimum-width integer types. + * + * The standard requires that exact-width type be defined for 8-, 16-, 32-, and + * 64-bit types if they are implemented. Other exact width types are optional. + * This implementation defines an exact-width types for every integer width + * that is represented in the standard integer types. + * + * The standard also requires minimum-width types be defined for 8-, 16-, 32-, + * and 64-bit widths regardless of whether there are corresponding exact-width + * types. + * + * To accommodate targets that are missing types that are exactly 8, 16, 32, or + * 64 bits wide, this implementation takes an approach of cascading + * redefinitions, redefining __int_leastN_t to successively smaller exact-width + * types. It is therefore important that the types are defined in order of + * descending widths. * - * Assume int to be the fastest type for all types with a width - * less than __INT_MAX__ rsp. INT_MAX + * We currently assume that the minimum-width types and the fastest + * minimum-width types are the same. This is allowed by the standard, but is + * suboptimal. + * + * In violation of the standard, some targets do not implement a type that is + * wide enough to represent all of the required widths (8-, 16-, 32-, 64-bit). + * To accommodate these targets, a required minimum-width type is only + * defined if there exists an exact-width type of equal or greater width. */ -#if __STDINT_EXP(INT_MAX) >= 0x7f -typedef signed int int_fast8_t; -typedef unsigned int uint_fast8_t; -#define __int_fast8_t_defined 1 -#endif - -#if __STDINT_EXP(INT_MAX) >= 0x7fff -typedef signed int int_fast16_t; -typedef unsigned int uint_fast16_t; -#define __int_fast16_t_defined 1 -#endif -#if __STDINT_EXP(INT_MAX) >= 0x7fffffff -typedef signed int int_fast32_t; -typedef unsigned int uint_fast32_t; -#define __int_fast32_t_defined 1 -#endif - -#if __STDINT_EXP(INT_MAX) > 0x7fffffff -typedef signed int int_fast64_t; -typedef unsigned int uint_fast64_t; -#define __int_fast64_t_defined 1 -#endif - -/* - * Fall back to [u]int_least_t for [u]int_fast_t types - * not having been defined, yet. - * Leave undefined, if [u]int_least_t should not be available. +#ifdef __INT64_TYPE__ +#ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/ +typedef __INT64_TYPE__ int64_t; +#endif /* __int8_t_defined */ +typedef __UINT64_TYPE__ uint64_t; +#undef __int_least64_t +#define __int_least64_t int64_t +#undef __uint_least64_t +#define __uint_least64_t uint64_t +#undef __int_least32_t +#define __int_least32_t int64_t +#undef __uint_least32_t +#define __uint_least32_t uint64_t +#undef __int_least16_t +#define __int_least16_t int64_t +#undef __uint_least16_t +#define __uint_least16_t uint64_t +#undef __int_least8_t +#define __int_least8_t int64_t +#undef __uint_least8_t +#define __uint_least8_t uint64_t +#endif /* __INT64_TYPE__ */ + +#ifdef __int_least64_t +typedef __int_least64_t int_least64_t; +typedef __uint_least64_t uint_least64_t; +typedef __int_least64_t int_fast64_t; +typedef __uint_least64_t uint_fast64_t; +#endif /* __int_least64_t */ + +#ifdef __INT56_TYPE__ +typedef __INT56_TYPE__ int56_t; +typedef __UINT56_TYPE__ uint56_t; +typedef int56_t int_least56_t; +typedef uint56_t uint_least56_t; +typedef int56_t int_fast56_t; +typedef uint56_t uint_fast56_t; +#undef __int_least32_t +#define __int_least32_t int56_t +#undef __uint_least32_t +#define __uint_least32_t uint56_t +#undef __int_least16_t +#define __int_least16_t int56_t +#undef __uint_least16_t +#define __uint_least16_t uint56_t +#undef __int_least8_t +#define __int_least8_t int56_t +#undef __uint_least8_t +#define __uint_least8_t uint56_t +#endif /* __INT56_TYPE__ */ + +#ifdef __INT48_TYPE__ +typedef __INT48_TYPE__ int48_t; +typedef __UINT48_TYPE__ uint48_t; +typedef int48_t int_least48_t; +typedef uint48_t uint_least48_t; +typedef int48_t int_fast48_t; +typedef uint48_t uint_fast48_t; +#undef __int_least32_t +#define __int_least32_t int48_t +#undef __uint_least32_t +#define __uint_least32_t uint48_t +#undef __int_least16_t +#define __int_least16_t int48_t +#undef __uint_least16_t +#define __uint_least16_t uint48_t +#undef __int_least8_t +#define __int_least8_t int48_t +#undef __uint_least8_t +#define __uint_least8_t uint48_t +#endif /* __INT48_TYPE__ */ + +#ifdef __INT40_TYPE__ +typedef __INT40_TYPE__ int40_t; +typedef __UINT40_TYPE__ uint40_t; +typedef int40_t int_least40_t; +typedef uint40_t uint_least40_t; +typedef int40_t int_fast40_t; +typedef uint40_t uint_fast40_t; +#undef __int_least32_t +#define __int_least32_t int40_t +#undef __uint_least32_t +#define __uint_least32_t uint40_t +#undef __int_least16_t +#define __int_least16_t int40_t +#undef __uint_least16_t +#define __uint_least16_t uint40_t +#undef __int_least8_t +#define __int_least8_t int40_t +#undef __uint_least8_t +#define __uint_least8_t uint40_t +#endif /* __INT40_TYPE__ */ + +#ifdef __INT32_TYPE__ + +#ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/ +typedef __INT32_TYPE__ int32_t; +#endif /* __int8_t_defined */ + +#ifndef __uint32_t_defined /* more glibc compatibility */ +#define __uint32_t_defined +typedef __UINT32_TYPE__ uint32_t; +#endif /* __uint32_t_defined */ + +#undef __int_least32_t +#define __int_least32_t int32_t +#undef __uint_least32_t +#define __uint_least32_t uint32_t +#undef __int_least16_t +#define __int_least16_t int32_t +#undef __uint_least16_t +#define __uint_least16_t uint32_t +#undef __int_least8_t +#define __int_least8_t int32_t +#undef __uint_least8_t +#define __uint_least8_t uint32_t +#endif /* __INT32_TYPE__ */ + +#ifdef __int_least32_t +typedef __int_least32_t int_least32_t; +typedef __uint_least32_t uint_least32_t; +typedef __int_least32_t int_fast32_t; +typedef __uint_least32_t uint_fast32_t; +#endif /* __int_least32_t */ + +#ifdef __INT24_TYPE__ +typedef __INT24_TYPE__ int24_t; +typedef __UINT24_TYPE__ uint24_t; +typedef int24_t int_least24_t; +typedef uint24_t uint_least24_t; +typedef int24_t int_fast24_t; +typedef uint24_t uint_fast24_t; +#undef __int_least16_t +#define __int_least16_t int24_t +#undef __uint_least16_t +#define __uint_least16_t uint24_t +#undef __int_least8_t +#define __int_least8_t int24_t +#undef __uint_least8_t +#define __uint_least8_t uint24_t +#endif /* __INT24_TYPE__ */ + +#ifdef __INT16_TYPE__ +#ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/ +typedef __INT16_TYPE__ int16_t; +#endif /* __int8_t_defined */ +typedef __UINT16_TYPE__ uint16_t; +#undef __int_least16_t +#define __int_least16_t int16_t +#undef __uint_least16_t +#define __uint_least16_t uint16_t +#undef __int_least8_t +#define __int_least8_t int16_t +#undef __uint_least8_t +#define __uint_least8_t uint16_t +#endif /* __INT16_TYPE__ */ + +#ifdef __int_least16_t +typedef __int_least16_t int_least16_t; +typedef __uint_least16_t uint_least16_t; +typedef __int_least16_t int_fast16_t; +typedef __uint_least16_t uint_fast16_t; +#endif /* __int_least16_t */ + +#ifdef __INT8_TYPE__ +#ifndef __int8_t_defined /* glibc sys/types.h also defines int8_t*/ +typedef __INT8_TYPE__ int8_t; +#endif /* __int8_t_defined */ +typedef __UINT8_TYPE__ uint8_t; +#undef __int_least8_t +#define __int_least8_t int8_t +#undef __uint_least8_t +#define __uint_least8_t uint8_t +#endif /* __INT8_TYPE__ */ + +#ifdef __int_least8_t +typedef __int_least8_t int_least8_t; +typedef __uint_least8_t uint_least8_t; +typedef __int_least8_t int_fast8_t; +typedef __uint_least8_t uint_fast8_t; +#endif /* __int_least8_t */ + +/* prevent glibc sys/types.h from defining conflicting types */ +#ifndef __int8_t_defined +#define __int8_t_defined +#endif /* __int8_t_defined */ + +/* C99 7.18.1.4 Integer types capable of holding object pointers. */ -#if !__int_fast8_t_defined -#if __int_least8_t_defined -typedef int_least8_t int_fast8_t; -typedef uint_least8_t uint_fast8_t; -#define __int_fast8_t_defined 1 -#endif -#endif - -#if !__int_fast16_t_defined -#if __int_least16_t_defined -typedef int_least16_t int_fast16_t; -typedef uint_least16_t uint_fast16_t; -#define __int_fast16_t_defined 1 -#endif -#endif +#define __stdint_join3(a, b, c) a##b##c -#if !__int_fast32_t_defined -#if __int_least32_t_defined -typedef int_least32_t int_fast32_t; -typedef uint_least32_t uint_fast32_t; -#define __int_fast32_t_defined 1 +#ifndef _INTPTR_T +#ifndef __intptr_t_defined +typedef __INTPTR_TYPE__ intptr_t; +#define __intptr_t_defined +#define _INTPTR_T #endif #endif -#if !__int_fast64_t_defined -#if __int_least64_t_defined -typedef int_least64_t int_fast64_t; -typedef uint_least64_t uint_fast64_t; -#define __int_fast64_t_defined 1 -#endif +#ifndef _UINTPTR_T +typedef __UINTPTR_TYPE__ uintptr_t; +#define _UINTPTR_T #endif -/* Greatest-width integer types */ -/* Modern GCCs provide __INTMAX_TYPE__ */ -#if defined(__INTMAX_TYPE__) +/* C99 7.18.1.5 Greatest-width integer types. + */ typedef __INTMAX_TYPE__ intmax_t; -#elif __have_longlong64 -typedef signed long long intmax_t; -#else -typedef signed long intmax_t; -#endif - -/* Modern GCCs provide __UINTMAX_TYPE__ */ -#if defined(__UINTMAX_TYPE__) typedef __UINTMAX_TYPE__ uintmax_t; -#elif __have_longlong64 -typedef unsigned long long uintmax_t; -#else -typedef unsigned long uintmax_t; -#endif -/* - * GCC doesn't provide an appropriate macro for [u]intptr_t - * For now, use __PTRDIFF_TYPE__ +/* C99 7.18.4 Macros for minimum-width integer constants. + * + * The standard requires that integer constant macros be defined for all the + * minimum-width types defined above. As 8-, 16-, 32-, and 64-bit minimum-width + * types are required, the corresponding integer constant macros are defined + * here. This implementation also defines minimum-width types for every other + * integer width that the target implements, so corresponding macros are + * defined below, too. + * + * These macros are defined using the same successive-shrinking approach as + * the type definitions above. It is likewise important that macros are defined + * in order of decending width. + * + * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the + * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]). */ -#if defined(__PTRDIFF_TYPE__) -typedef signed __PTRDIFF_TYPE__ intptr_t; -typedef unsigned __PTRDIFF_TYPE__ uintptr_t; -#define INTPTR_MAX PTRDIFF_MAX -#define INTPTR_MIN PTRDIFF_MIN -#ifdef __UINTPTR_MAX__ -#define UINTPTR_MAX __UINTPTR_MAX__ + +#define __int_c_join(a, b) a##b +#define __int_c(v, suffix) __int_c_join(v, suffix) +#define __uint_c(v, suffix) __int_c_join(v##U, suffix) + +#ifdef __INT64_TYPE__ +#undef __int64_c_suffix +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT64_C_SUFFIX__ +#define __int64_c_suffix __INT64_C_SUFFIX__ +#define __int32_c_suffix __INT64_C_SUFFIX__ +#define __int16_c_suffix __INT64_C_SUFFIX__ +#define __int8_c_suffix __INT64_C_SUFFIX__ +#endif /* __INT64_C_SUFFIX__ */ +#endif /* __INT64_TYPE__ */ + +#ifdef __int_least64_t +#ifdef __int64_c_suffix +#define INT64_C(v) __int_c(v, __int64_c_suffix) +#define UINT64_C(v) __uint_c(v, __int64_c_suffix) #else -#define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1) -#endif +#define INT64_C(v) v +#define UINT64_C(v) v##U +#endif /* __int64_c_suffix */ +#endif /* __int_least64_t */ + +#ifdef __INT56_TYPE__ +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT56_C_SUFFIX__ +#define INT56_C(v) __int_c(v, __INT56_C_SUFFIX__) +#define UINT56_C(v) __uint_c(v, __INT56_C_SUFFIX__) +#define __int32_c_suffix __INT56_C_SUFFIX__ +#define __int16_c_suffix __INT56_C_SUFFIX__ +#define __int8_c_suffix __INT56_C_SUFFIX__ #else -/* - * Fallback to hardcoded values, - * should be valid on cpu's with 32bit int/32bit void* - */ -typedef signed long intptr_t; -typedef unsigned long uintptr_t; -#define INTPTR_MAX __STDINT_EXP(LONG_MAX) -#define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1) -#define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) -#endif - -/* Limits of Specified-Width Integer Types */ - -#if __int8_t_defined -#define INT8_MIN -128 -#define INT8_MAX 127 -#define UINT8_MAX 255 -#endif - -#if __int_least8_t_defined -#define INT_LEAST8_MIN -128 -#define INT_LEAST8_MAX 127 -#define UINT_LEAST8_MAX 255 +#define INT56_C(v) v +#define UINT56_C(v) v##U +#endif /* __INT56_C_SUFFIX__ */ +#endif /* __INT56_TYPE__ */ + +#ifdef __INT48_TYPE__ +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT48_C_SUFFIX__ +#define INT48_C(v) __int_c(v, __INT48_C_SUFFIX__) +#define UINT48_C(v) __uint_c(v, __INT48_C_SUFFIX__) +#define __int32_c_suffix __INT48_C_SUFFIX__ +#define __int16_c_suffix __INT48_C_SUFFIX__ +#define __int8_c_suffix __INT48_C_SUFFIX__ #else -#error required type int_least8_t missing -#endif - -#if __int16_t_defined -#define INT16_MIN -32768 -#define INT16_MAX 32767 -#define UINT16_MAX 65535 -#endif - -#if __int_least16_t_defined -#define INT_LEAST16_MIN -32768 -#define INT_LEAST16_MAX 32767 -#define UINT_LEAST16_MAX 65535 +#define INT48_C(v) v +#define UINT48_C(v) v##U +#endif /* __INT48_C_SUFFIX__ */ +#endif /* __INT48_TYPE__ */ + +#ifdef __INT40_TYPE__ +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT40_C_SUFFIX__ +#define INT40_C(v) __int_c(v, __INT40_C_SUFFIX__) +#define UINT40_C(v) __uint_c(v, __INT40_C_SUFFIX__) +#define __int32_c_suffix __INT40_C_SUFFIX__ +#define __int16_c_suffix __INT40_C_SUFFIX__ +#define __int8_c_suffix __INT40_C_SUFFIX__ #else -#error required type int_least16_t missing -#endif - -#if __int32_t_defined -#if __have_long32 -#define INT32_MIN (-2147483647L - 1) -#define INT32_MAX 2147483647L -#define UINT32_MAX 4294967295UL +#define INT40_C(v) v +#define UINT40_C(v) v##U +#endif /* __INT40_C_SUFFIX__ */ +#endif /* __INT40_TYPE__ */ + +#ifdef __INT32_TYPE__ +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT32_C_SUFFIX__ +#define __int32_c_suffix __INT32_C_SUFFIX__ +#define __int16_c_suffix __INT32_C_SUFFIX__ +#define __int8_c_suffix __INT32_C_SUFFIX__ +#endif /* __INT32_C_SUFFIX__ */ +#endif /* __INT32_TYPE__ */ + +#ifdef __int_least32_t +#ifdef __int32_c_suffix +#define INT32_C(v) __int_c(v, __int32_c_suffix) +#define UINT32_C(v) __uint_c(v, __int32_c_suffix) #else -#define INT32_MIN (-2147483647 - 1) -#define INT32_MAX 2147483647 -#define UINT32_MAX 4294967295U -#endif -#endif - -#if __int_least32_t_defined -#if __have_long32 -#define INT_LEAST32_MIN (-2147483647L - 1) -#define INT_LEAST32_MAX 2147483647L -#define UINT_LEAST32_MAX 4294967295UL +#define INT32_C(v) v +#define UINT32_C(v) v##U +#endif /* __int32_c_suffix */ +#endif /* __int_least32_t */ + +#ifdef __INT24_TYPE__ +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT24_C_SUFFIX__ +#define INT24_C(v) __int_c(v, __INT24_C_SUFFIX__) +#define UINT24_C(v) __uint_c(v, __INT24_C_SUFFIX__) +#define __int16_c_suffix __INT24_C_SUFFIX__ +#define __int8_c_suffix __INT24_C_SUFFIX__ #else -#define INT_LEAST32_MIN (-2147483647 - 1) -#define INT_LEAST32_MAX 2147483647 -#define UINT_LEAST32_MAX 4294967295U -#endif +#define INT24_C(v) v +#define UINT24_C(v) v##U +#endif /* __INT24_C_SUFFIX__ */ +#endif /* __INT24_TYPE__ */ + +#ifdef __INT16_TYPE__ +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT16_C_SUFFIX__ +#define __int16_c_suffix __INT16_C_SUFFIX__ +#define __int8_c_suffix __INT16_C_SUFFIX__ +#endif /* __INT16_C_SUFFIX__ */ +#endif /* __INT16_TYPE__ */ + +#ifdef __int_least16_t +#ifdef __int16_c_suffix +#define INT16_C(v) __int_c(v, __int16_c_suffix) +#define UINT16_C(v) __uint_c(v, __int16_c_suffix) #else -#error required type int_least32_t missing -#endif - -#if __int64_t_defined -#if __have_long64 -#define INT64_MIN (-9223372036854775807L - 1L) -#define INT64_MAX 9223372036854775807L -#define UINT64_MAX 18446744073709551615U -#elif __have_longlong64 -#define INT64_MIN (-9223372036854775807LL - 1LL) -#define INT64_MAX 9223372036854775807LL -#define UINT64_MAX 18446744073709551615ULL -#endif -#endif - -#if __int_least64_t_defined -#if __have_long64 -#define INT_LEAST64_MIN (-9223372036854775807L - 1L) -#define INT_LEAST64_MAX 9223372036854775807L -#define UINT_LEAST64_MAX 18446744073709551615U -#elif __have_longlong64 -#define INT_LEAST64_MIN (-9223372036854775807LL - 1LL) -#define INT_LEAST64_MAX 9223372036854775807LL -#define UINT_LEAST64_MAX 18446744073709551615ULL -#endif -#endif - -#if __int_fast8_t_defined -#if __STDINT_EXP(INT_MAX) >= 0x7f -#define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX) - 1) -#define INT_FAST8_MAX __STDINT_EXP(INT_MAX) -#define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) +#define INT16_C(v) v +#define UINT16_C(v) v##U +#endif /* __int16_c_suffix */ +#endif /* __int_least16_t */ + +#ifdef __INT8_TYPE__ +#undef __int8_c_suffix +#ifdef __INT8_C_SUFFIX__ +#define __int8_c_suffix __INT8_C_SUFFIX__ +#endif /* __INT8_C_SUFFIX__ */ +#endif /* __INT8_TYPE__ */ + +#ifdef __int_least8_t +#ifdef __int8_c_suffix +#define INT8_C(v) __int_c(v, __int8_c_suffix) +#define UINT8_C(v) __uint_c(v, __int8_c_suffix) #else -#define INT_FAST8_MIN INT_LEAST8_MIN -#define INT_FAST8_MAX INT_LEAST8_MAX -#define UINT_FAST8_MAX UINT_LEAST8_MAX -#endif -#endif +#define INT8_C(v) v +#define UINT8_C(v) v##U +#endif /* __int8_c_suffix */ +#endif /* __int_least8_t */ + +/* C99 7.18.2.1 Limits of exact-width integer types. + * C99 7.18.2.2 Limits of minimum-width integer types. + * C99 7.18.2.3 Limits of fastest minimum-width integer types. + * + * The presence of limit macros are completely optional in C99. This + * implementation defines limits for all of the types (exact- and + * minimum-width) that it defines above, using the limits of the minimum-width + * type for any types that do not have exact-width representations. + * + * As in the type definitions, this section takes an approach of + * successive-shrinking to determine which limits to use for the standard (8, + * 16, 32, 64) bit widths when they don't have exact representations. It is + * therefore important that the definitions be kept in order of decending + * widths. + * + * Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the + * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]). + */ -#if __int_fast16_t_defined -#if __STDINT_EXP(INT_MAX) >= 0x7fff -#define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX) - 1) -#define INT_FAST16_MAX __STDINT_EXP(INT_MAX) -#define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) -#else -#define INT_FAST16_MIN INT_LEAST16_MIN -#define INT_FAST16_MAX INT_LEAST16_MAX -#define UINT_FAST16_MAX UINT_LEAST16_MAX -#endif -#endif +#ifdef __INT64_TYPE__ +#define INT64_MAX INT64_C(9223372036854775807) +#define INT64_MIN (-INT64_C(9223372036854775807) - 1) +#define UINT64_MAX UINT64_C(18446744073709551615) + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT64_WIDTH 64 +#define INT64_WIDTH UINT64_WIDTH + +#define __UINT_LEAST64_WIDTH UINT64_WIDTH +#undef __UINT_LEAST32_WIDTH +#define __UINT_LEAST32_WIDTH UINT64_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT64_WIDTH +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT64_MAX +#endif /* __STDC_VERSION__ */ + +#define __INT_LEAST64_MIN INT64_MIN +#define __INT_LEAST64_MAX INT64_MAX +#define __UINT_LEAST64_MAX UINT64_MAX +#undef __INT_LEAST32_MIN +#define __INT_LEAST32_MIN INT64_MIN +#undef __INT_LEAST32_MAX +#define __INT_LEAST32_MAX INT64_MAX +#undef __UINT_LEAST32_MAX +#define __UINT_LEAST32_MAX UINT64_MAX +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT64_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT64_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT64_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT64_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT64_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT64_MAX +#endif /* __INT64_TYPE__ */ + +#ifdef __INT_LEAST64_MIN +#define INT_LEAST64_MIN __INT_LEAST64_MIN +#define INT_LEAST64_MAX __INT_LEAST64_MAX +#define UINT_LEAST64_MAX __UINT_LEAST64_MAX +#define INT_FAST64_MIN __INT_LEAST64_MIN +#define INT_FAST64_MAX __INT_LEAST64_MAX +#define UINT_FAST64_MAX __UINT_LEAST64_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT_LEAST64_WIDTH __UINT_LEAST64_WIDTH +#define INT_LEAST64_WIDTH UINT_LEAST64_WIDTH +#define UINT_FAST64_WIDTH __UINT_LEAST64_WIDTH +#define INT_FAST64_WIDTH UINT_FAST64_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST64_MIN */ + +#ifdef __INT56_TYPE__ +#define INT56_MAX INT56_C(36028797018963967) +#define INT56_MIN (-INT56_C(36028797018963967) - 1) +#define UINT56_MAX UINT56_C(72057594037927935) +#define INT_LEAST56_MIN INT56_MIN +#define INT_LEAST56_MAX INT56_MAX +#define UINT_LEAST56_MAX UINT56_MAX +#define INT_FAST56_MIN INT56_MIN +#define INT_FAST56_MAX INT56_MAX +#define UINT_FAST56_MAX UINT56_MAX + +#undef __INT_LEAST32_MIN +#define __INT_LEAST32_MIN INT56_MIN +#undef __INT_LEAST32_MAX +#define __INT_LEAST32_MAX INT56_MAX +#undef __UINT_LEAST32_MAX +#define __UINT_LEAST32_MAX UINT56_MAX +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT56_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT56_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT56_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT56_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT56_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT56_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT56_WIDTH 56 +#define INT56_WIDTH UINT56_WIDTH +#define UINT_LEAST56_WIDTH UINT56_WIDTH +#define INT_LEAST56_WIDTH UINT_LEAST56_WIDTH +#define UINT_FAST56_WIDTH UINT56_WIDTH +#define INT_FAST56_WIDTH UINT_FAST56_WIDTH +#undef __UINT_LEAST32_WIDTH +#define __UINT_LEAST32_WIDTH UINT56_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT56_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT56_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT56_TYPE__ */ + +#ifdef __INT48_TYPE__ +#define INT48_MAX INT48_C(140737488355327) +#define INT48_MIN (-INT48_C(140737488355327) - 1) +#define UINT48_MAX UINT48_C(281474976710655) +#define INT_LEAST48_MIN INT48_MIN +#define INT_LEAST48_MAX INT48_MAX +#define UINT_LEAST48_MAX UINT48_MAX +#define INT_FAST48_MIN INT48_MIN +#define INT_FAST48_MAX INT48_MAX +#define UINT_FAST48_MAX UINT48_MAX + +#undef __INT_LEAST32_MIN +#define __INT_LEAST32_MIN INT48_MIN +#undef __INT_LEAST32_MAX +#define __INT_LEAST32_MAX INT48_MAX +#undef __UINT_LEAST32_MAX +#define __UINT_LEAST32_MAX UINT48_MAX +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT48_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT48_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT48_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT48_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT48_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT48_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT48_WIDTH 48 +#define INT48_WIDTH UINT48_WIDTH +#define UINT_LEAST48_WIDTH UINT48_WIDTH +#define INT_LEAST48_WIDTH UINT_LEAST48_WIDTH +#define UINT_FAST48_WIDTH UINT48_WIDTH +#define INT_FAST48_WIDTH UINT_FAST48_WIDTH +#undef __UINT_LEAST32_WIDTH +#define __UINT_LEAST32_WIDTH UINT48_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT48_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT48_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT48_TYPE__ */ + +#ifdef __INT40_TYPE__ +#define INT40_MAX INT40_C(549755813887) +#define INT40_MIN (-INT40_C(549755813887) - 1) +#define UINT40_MAX UINT40_C(1099511627775) +#define INT_LEAST40_MIN INT40_MIN +#define INT_LEAST40_MAX INT40_MAX +#define UINT_LEAST40_MAX UINT40_MAX +#define INT_FAST40_MIN INT40_MIN +#define INT_FAST40_MAX INT40_MAX +#define UINT_FAST40_MAX UINT40_MAX + +#undef __INT_LEAST32_MIN +#define __INT_LEAST32_MIN INT40_MIN +#undef __INT_LEAST32_MAX +#define __INT_LEAST32_MAX INT40_MAX +#undef __UINT_LEAST32_MAX +#define __UINT_LEAST32_MAX UINT40_MAX +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT40_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT40_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT40_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT40_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT40_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT40_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT40_WIDTH 40 +#define INT40_WIDTH UINT40_WIDTH +#define UINT_LEAST40_WIDTH UINT40_WIDTH +#define INT_LEAST40_WIDTH UINT_LEAST40_WIDTH +#define UINT_FAST40_WIDTH UINT40_WIDTH +#define INT_FAST40_WIDTH UINT_FAST40_WIDTH +#undef __UINT_LEAST32_WIDTH +#define __UINT_LEAST32_WIDTH UINT40_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT40_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT40_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT40_TYPE__ */ + +#ifdef __INT32_TYPE__ +#define INT32_MAX INT32_C(2147483647) +#define INT32_MIN (-INT32_C(2147483647) - 1) +#define UINT32_MAX UINT32_C(4294967295) + +#undef __INT_LEAST32_MIN +#define __INT_LEAST32_MIN INT32_MIN +#undef __INT_LEAST32_MAX +#define __INT_LEAST32_MAX INT32_MAX +#undef __UINT_LEAST32_MAX +#define __UINT_LEAST32_MAX UINT32_MAX +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT32_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT32_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT32_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT32_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT32_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT32_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT32_WIDTH 32 +#define INT32_WIDTH UINT32_WIDTH +#undef __UINT_LEAST32_WIDTH +#define __UINT_LEAST32_WIDTH UINT32_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT32_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT32_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT32_TYPE__ */ + +#ifdef __INT_LEAST32_MIN +#define INT_LEAST32_MIN __INT_LEAST32_MIN +#define INT_LEAST32_MAX __INT_LEAST32_MAX +#define UINT_LEAST32_MAX __UINT_LEAST32_MAX +#define INT_FAST32_MIN __INT_LEAST32_MIN +#define INT_FAST32_MAX __INT_LEAST32_MAX +#define UINT_FAST32_MAX __UINT_LEAST32_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT_LEAST32_WIDTH __UINT_LEAST32_WIDTH +#define INT_LEAST32_WIDTH UINT_LEAST32_WIDTH +#define UINT_FAST32_WIDTH __UINT_LEAST32_WIDTH +#define INT_FAST32_WIDTH UINT_FAST32_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST32_MIN */ + +#ifdef __INT24_TYPE__ +#define INT24_MAX INT24_C(8388607) +#define INT24_MIN (-INT24_C(8388607) - 1) +#define UINT24_MAX UINT24_C(16777215) +#define INT_LEAST24_MIN INT24_MIN +#define INT_LEAST24_MAX INT24_MAX +#define UINT_LEAST24_MAX UINT24_MAX +#define INT_FAST24_MIN INT24_MIN +#define INT_FAST24_MAX INT24_MAX +#define UINT_FAST24_MAX UINT24_MAX + +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT24_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT24_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT24_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT24_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT24_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT24_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT24_WIDTH 24 +#define INT24_WIDTH UINT24_WIDTH +#define UINT_LEAST24_WIDTH UINT24_WIDTH +#define INT_LEAST24_WIDTH UINT_LEAST24_WIDTH +#define UINT_FAST24_WIDTH UINT24_WIDTH +#define INT_FAST24_WIDTH UINT_FAST24_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT24_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT24_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT24_TYPE__ */ + +#ifdef __INT16_TYPE__ +#define INT16_MAX INT16_C(32767) +#define INT16_MIN (-INT16_C(32767) - 1) +#define UINT16_MAX UINT16_C(65535) + +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT16_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT16_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT16_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT16_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT16_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT16_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT16_WIDTH 16 +#define INT16_WIDTH UINT16_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT16_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT16_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT16_TYPE__ */ + +#ifdef __INT_LEAST16_MIN +#define INT_LEAST16_MIN __INT_LEAST16_MIN +#define INT_LEAST16_MAX __INT_LEAST16_MAX +#define UINT_LEAST16_MAX __UINT_LEAST16_MAX +#define INT_FAST16_MIN __INT_LEAST16_MIN +#define INT_FAST16_MAX __INT_LEAST16_MAX +#define UINT_FAST16_MAX __UINT_LEAST16_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT_LEAST16_WIDTH __UINT_LEAST16_WIDTH +#define INT_LEAST16_WIDTH UINT_LEAST16_WIDTH +#define UINT_FAST16_WIDTH __UINT_LEAST16_WIDTH +#define INT_FAST16_WIDTH UINT_FAST16_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST16_MIN */ + +#ifdef __INT8_TYPE__ +#define INT8_MAX INT8_C(127) +#define INT8_MIN (-INT8_C(127) - 1) +#define UINT8_MAX UINT8_C(255) + +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT8_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT8_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT8_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT8_WIDTH 8 +#define INT8_WIDTH UINT8_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT8_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT8_TYPE__ */ + +#ifdef __INT_LEAST8_MIN +#define INT_LEAST8_MIN __INT_LEAST8_MIN +#define INT_LEAST8_MAX __INT_LEAST8_MAX +#define UINT_LEAST8_MAX __UINT_LEAST8_MAX +#define INT_FAST8_MIN __INT_LEAST8_MIN +#define INT_FAST8_MAX __INT_LEAST8_MAX +#define UINT_FAST8_MAX __UINT_LEAST8_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT_LEAST8_WIDTH __UINT_LEAST8_WIDTH +#define INT_LEAST8_WIDTH UINT_LEAST8_WIDTH +#define UINT_FAST8_WIDTH __UINT_LEAST8_WIDTH +#define INT_FAST8_WIDTH UINT_FAST8_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST8_MIN */ + +/* Some utility macros */ +#define __INTN_MIN(n) __stdint_join3(INT, n, _MIN) +#define __INTN_MAX(n) __stdint_join3(INT, n, _MAX) +#define __UINTN_MAX(n) __stdint_join3(UINT, n, _MAX) +#define __INTN_C(n, v) __stdint_join3(INT, n, _C(v)) +#define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v)) + +/* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */ +/* C99 7.18.3 Limits of other integer types. */ + +#define INTPTR_MIN (-__INTPTR_MAX__ - 1) +#define INTPTR_MAX __INTPTR_MAX__ +#define UINTPTR_MAX __UINTPTR_MAX__ +#define PTRDIFF_MIN (-__PTRDIFF_MAX__ - 1) +#define PTRDIFF_MAX __PTRDIFF_MAX__ +#define SIZE_MAX __SIZE_MAX__ -#if __int_fast32_t_defined -#if __STDINT_EXP(INT_MAX) >= 0x7fffffff -#define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX) - 1) -#define INT_FAST32_MAX __STDINT_EXP(INT_MAX) -#define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) -#else -#define INT_FAST32_MIN INT_LEAST32_MIN -#define INT_FAST32_MAX INT_LEAST32_MAX -#define UINT_FAST32_MAX UINT_LEAST32_MAX -#endif +/* C23 7.22.2.4 Width of integer types capable of holding object pointers. */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +/* NB: The C standard requires that these be the same value, but the compiler + exposes separate internal width macros. */ +#define INTPTR_WIDTH __INTPTR_WIDTH__ +#define UINTPTR_WIDTH __UINTPTR_WIDTH__ #endif -#if __int_fast64_t_defined -#if __STDINT_EXP(INT_MAX) > 0x7fffffff -#define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX) - 1) -#define INT_FAST64_MAX __STDINT_EXP(INT_MAX) -#define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) -#else -#define INT_FAST64_MIN INT_LEAST64_MIN -#define INT_FAST64_MAX INT_LEAST64_MAX -#define UINT_FAST64_MAX UINT_LEAST64_MAX -#endif +/* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__ + * is enabled. */ +#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 +#define RSIZE_MAX (SIZE_MAX >> 1) #endif -#ifdef __INTMAX_MAX__ +/* C99 7.18.2.5 Limits of greatest-width integer types. */ +#define INTMAX_MIN (-__INTMAX_MAX__ - 1) #define INTMAX_MAX __INTMAX_MAX__ -#define INTMAX_MIN (-INTMAX_MAX - 1) -#elif defined(__INTMAX_TYPE__) -/* All relevant GCC versions prefer long to long long for intmax_t. */ -#define INTMAX_MAX INT64_MAX -#define INTMAX_MIN INT64_MIN -#endif - -#ifdef __UINTMAX_MAX__ #define UINTMAX_MAX __UINTMAX_MAX__ -#elif defined(__UINTMAX_TYPE__) -/* All relevant GCC versions prefer long to long long for intmax_t. */ -#define UINTMAX_MAX UINT64_MAX -#endif -/* This must match size_t in stddef.h, currently long unsigned int */ -#ifdef __SIZE_MAX__ -#define SIZE_MAX __SIZE_MAX__ -#else -#define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) +/* C23 7.22.2.5 Width of greatest-width integer types. */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +/* NB: The C standard requires that these be the same value, but the compiler + exposes separate internal width macros. */ +#define INTMAX_WIDTH __INTMAX_WIDTH__ +#define UINTMAX_WIDTH __UINTMAX_WIDTH__ #endif -/* This must match sig_atomic_t in (currently int) */ -#define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1) -#define SIG_ATOMIC_MAX __STDINT_EXP(INT_MAX) - -/* This must match ptrdiff_t in (currently long int) */ -#ifdef __PTRDIFF_MAX__ -#define PTRDIFF_MAX __PTRDIFF_MAX__ +/* C99 7.18.3 Limits of other integer types. */ +#define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__) +#define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__) +#ifdef __WINT_UNSIGNED__ +#define WINT_MIN __UINTN_C(__WINT_WIDTH__, 0) +#define WINT_MAX __UINTN_MAX(__WINT_WIDTH__) #else -#define PTRDIFF_MAX __STDINT_EXP(LONG_MAX) +#define WINT_MIN __INTN_MIN(__WINT_WIDTH__) +#define WINT_MAX __INTN_MAX(__WINT_WIDTH__) #endif -#define PTRDIFF_MIN (-PTRDIFF_MAX - 1) -#ifdef __WCHAR_MAX__ +#ifndef WCHAR_MAX #define WCHAR_MAX __WCHAR_MAX__ #endif -#ifdef __WCHAR_MIN__ -#define WCHAR_MIN __WCHAR_MIN__ -#endif - -/* wint_t is unsigned int on almost all GCC targets. */ -#ifdef __WINT_MAX__ -#define WINT_MAX __WINT_MAX__ -#else -#define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) -#endif -#ifdef __WINT_MIN__ -#define WINT_MIN __WINT_MIN__ -#else -#define WINT_MIN 0U -#endif - -/** Macros for minimum-width integer constant expressions */ -#define INT8_C(x) x -#if __STDINT_EXP(INT_MAX) > 0x7f -#define UINT8_C(x) x -#else -#define UINT8_C(x) x##U -#endif - -#define INT16_C(x) x -#if __STDINT_EXP(INT_MAX) > 0x7fff -#define UINT16_C(x) x -#else -#define UINT16_C(x) x##U -#endif - -#if __have_long32 -#define INT32_C(x) x##L -#define UINT32_C(x) x##UL -#else -#define INT32_C(x) x -#define UINT32_C(x) x##U -#endif - -#if __int64_t_defined -#if __have_long64 -#define INT64_C(x) x##L -#define UINT64_C(x) x##UL +#ifndef WCHAR_MIN +#if __WCHAR_MAX__ == __INTN_MAX(__WCHAR_WIDTH__) +#define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__) #else -#define INT64_C(x) x##LL -#define UINT64_C(x) x##ULL +#define WCHAR_MIN __UINTN_C(__WCHAR_WIDTH__, 0) #endif #endif -/** Macros for greatest-width integer constant expression */ -#if __have_long64 -#define INTMAX_C(x) x##L -#define UINTMAX_C(x) x##UL -#else -#define INTMAX_C(x) x##LL -#define UINTMAX_C(x) x##ULL -#endif +/* 7.18.4.2 Macros for greatest-width integer constants. */ +#define INTMAX_C(v) __int_c(v, __INTMAX_C_SUFFIX__) +#define UINTMAX_C(v) __int_c(v, __UINTMAX_C_SUFFIX__) -#ifdef __cplusplus -} +/* C23 7.22.3.x Width of other integer types. */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define PTRDIFF_WIDTH __PTRDIFF_WIDTH__ +#define SIG_ATOMIC_WIDTH __SIG_ATOMIC_WIDTH__ +#define SIZE_WIDTH __SIZE_WIDTH__ +#define WCHAR_WIDTH __WCHAR_WIDTH__ +#define WINT_WIDTH __WINT_WIDTH__ #endif -#endif /* _STDINT_H */ +#endif /* __STDC_HOSTED__ */ +#endif /* __CLANG_STDINT_H */