1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2014, STMicroelectronics International N.V. 4 */ 5 6 /* 7 * This file provides what C99 standard requires in 8 * 7.18 interger types <stdint.h> 9 */ 10 11 #ifndef STDINT_H 12 #define STDINT_H 13 #define _STDINT_H 14 15 /* 16 * If compiler supplies neither __ILP32__ or __LP64__, try to figure it out 17 * here. 18 */ 19 #if !defined(__ILP32__) && !defined(__LP64__) 20 #if defined(__SIZEOF_INT__) && defined(__SIZEOF_POINTER__) && \ 21 defined(__SIZEOF_LONG__) 22 #if __SIZEOF_INT__ == 4 && __SIZEOF_POINTER__ == 4 && __SIZEOF_LONG__ == 4 23 #define __ILP32__ 1 24 #endif 25 #if __SIZEOF_INT__ == 4 && __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 8 26 #define __LP64__ 1 27 #endif 28 #endif 29 #endif /* !defined(__ILP32__) && !defined(__LP64__) */ 30 31 #if !defined(__ILP32__) && !defined(__LP64__) 32 #error Neither __ILP32__ nor __LP64__ is defined 33 #endif 34 35 #ifndef ASM 36 37 /* 7.18.1.1 Exact-width interger types */ 38 #ifndef __int8_t_defined 39 # define __int8_t_defined 40 typedef signed char int8_t; 41 typedef short int int16_t; 42 typedef int int32_t; 43 #ifdef __ILP32__ 44 __extension__ 45 typedef long long int int64_t; 46 #endif /*__ILP32__*/ 47 #ifdef __LP64__ 48 typedef long int int64_t; 49 #endif /*__LP64__*/ 50 #endif 51 52 /* Unsigned. */ 53 typedef unsigned char uint8_t; 54 typedef unsigned short int uint16_t; 55 #ifndef __uint32_t_defined 56 typedef unsigned int uint32_t; 57 # define __uint32_t_defined 58 #endif 59 #ifdef __ILP32__ 60 __extension__ 61 typedef unsigned long long int uint64_t; 62 #endif /*__ILP32__*/ 63 #ifdef __LP64__ 64 typedef unsigned long int uint64_t; 65 #endif /*__LP64__*/ 66 67 /* 7.18.1.2 Minimum-width integer types */ 68 typedef int8_t int_least8_t; 69 typedef int16_t int_least16_t; 70 typedef int32_t int_least32_t; 71 typedef int64_t int_least64_t; 72 typedef uint8_t uint_least8_t; 73 typedef uint16_t uint_least16_t; 74 typedef uint32_t uint_least32_t; 75 typedef uint64_t uint_least64_t; 76 77 /* 7.18.1.3 Fastest minimum-width integer types */ 78 typedef int8_t int_fast8_t; 79 typedef int16_t int_fast16_t; 80 typedef int32_t int_fast32_t; 81 typedef int64_t int_fast64_t; 82 typedef uint8_t uint_fast8_t; 83 typedef uint16_t uint_fast16_t; 84 typedef uint32_t uint_fast32_t; 85 typedef uint64_t uint_fast64_t; 86 87 /* 7.18.1.4 Integer types capable of holding object pointers */ 88 typedef long intptr_t; 89 typedef unsigned long uintptr_t; 90 91 typedef int64_t intmax_t; 92 typedef uint64_t uintmax_t; 93 94 #endif /*ASM*/ 95 96 /* 97 * 7.18.2 Limits of specified-width integer types 98 */ 99 100 /* 7.18.2.1 Limits of exact-width interger types */ 101 102 #define INT8_MIN (-0x7f-1) 103 #define INT16_MIN (-0x7fff-1) 104 #define INT32_MIN (-0x7fffffff-1) 105 #define INT64_MIN (-0x7fffffffffffffffL-1) 106 107 #define INT8_MAX 0x7f 108 #define INT16_MAX 0x7fff 109 #define INT32_MAX 0x7fffffff 110 #define INT64_MAX 0x7fffffffffffffffL 111 112 #define UINT8_MAX 0xff 113 #define UINT16_MAX 0xffff 114 #define UINT32_MAX 0xffffffffU 115 #define UINT64_MAX 0xffffffffffffffffUL 116 117 /* 7.18.2.2 Limits of minimum-width integer types */ 118 119 #define INT_LEAST8_MIN INT8_MIN 120 #define INT_LEAST16_MIN INT16_MIN 121 #define INT_LEAST32_MIN INT32_MIN 122 #define INT_LEAST64_MIN INT64_MIN 123 124 #define INT_LEAST8_MAX INT8_MAX 125 #define INT_LEAST16_MAX INT16_MAX 126 #define INT_LEAST32_MAX INT32_MAX 127 #define INT_LEAST64_MAX INT64_MAX 128 129 #define UINT_LEAST8_MAX UINT8_MAX 130 #define UINT_LEAST16_MAX UINT16_MAX 131 #define UINT_LEAST32_MAX UINT32_MAX 132 #define UINT_LEAST64_MAX UINT64_MAX 133 134 /* 7.18.2.3 Limits of fastest minimum-width integer types */ 135 136 #define INT_FAST8_MIN INT8_MIN 137 #define INT_FAST16_MIN INT16_MIN 138 #define INT_FAST32_MIN INT32_MIN 139 #define INT_FAST64_MIN INT64_MIN 140 141 #define INT_FAST8_MAX INT8_MAX 142 #define INT_FAST16_MAX INT16_MAX 143 #define INT_FAST32_MAX INT32_MAX 144 #define INT_FAST64_MAX INT64_MAX 145 146 #define UINT_FAST8_MAX UINT8_MAX 147 #define UINT_FAST16_MAX UINT16_MAX 148 #define UINT_FAST32_MAX UINT32_MAX 149 #define UINT_FAST64_MAX UINT64_MAX 150 151 /* 7.18.2.4 Limits of integer types capable of holding object pointers */ 152 153 #define INTPTR_MIN LONG_MIN 154 #define INTPTR_MAX LONG_MAX 155 #define UINTPTR_MAX ULONG_MAX 156 157 /* 7.18.2.5 Limits of greatest-width integer types */ 158 #define INTMAX_MAX INT64_MAX 159 #define INTMAX_MIN INT64_MIN 160 #define UINTMAX_MAX UINT64_MAX 161 162 /* 7.18.3 Limits of other integer types */ 163 #define SIZE_MAX ULONG_MAX 164 165 /* 166 * 7.18.4 Macros for integer constants 167 */ 168 169 /* 7.18.4.1 Macros for minimum-width integer constants */ 170 171 #define INT8_C(v) v 172 #define UINT8_C(v) v 173 #define INT16_C(v) v 174 #define UINT16_C(v) v 175 #define INT32_C(v) v 176 #define UINT32_C(v) v ## U 177 #ifdef __ILP32__ 178 #define INT64_C(v) v ## LL 179 #define UINT64_C(v) v ## ULL 180 #endif 181 #ifdef __LP64__ 182 #define INT64_C(v) v ## L 183 #define UINT64_C(v) v ## UL 184 #endif 185 186 #ifdef ASM 187 #define UINTPTR_C(v) v 188 #else 189 #define UINTPTR_C(v) v ## LU 190 #endif 191 192 /* 7.18.4.2 Macros for greatest-width integer constants */ 193 194 #define INTMAX_C(v) INT64_C(v) 195 #define UINTMAX_C(v) UINT64_C(v) 196 197 198 #endif /* STDINT_H */ 199