1 // Copyright 2016 The Fuchsia Authors 2 // 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file or at 5 // https://opensource.org/licenses/MIT 6 7 #pragma once 8 9 // The compiler predefines macros __<type>_TYPE__, __<type>_MAX__, 10 // and __<type>_C for the various types. All we have to do here is 11 // define the public names based on those macros. 12 13 // Clang predefines macros __<type>_FMT<letter>__ for each type, 14 // with <letter> being i and for signed types, and o, u, x, and X 15 // for unsigned types. That lets <inttypes.h> do its work without 16 // any special knowledge of what the underlying types are. 17 // Unfortunately, GCC does not define these macros. To keep all 18 // knowledge of the compiler's choices isolated to this file, define 19 // them here for GCC so that <inttypes.h> can use them unconditionally. 20 #ifndef __INTMAX_FMTd__ 21 22 #define __INT8_FMT_MODIFIER__ "hh" 23 #define __INT16_FMT_MODIFIER__ "h" 24 #define __INT32_FMT_MODIFIER__ "" 25 26 #define __INT_LEAST8_FMT_MODIFIER__ __INT8_FMT_MODIFIER__ 27 #define __INT_LEAST16_FMT_MODIFIER__ __INT16_FMT_MODIFIER__ 28 #define __INT_LEAST32_FMT_MODIFIER__ __INT32_FMT_MODIFIER__ 29 #define __INT_LEAST64_FMT_MODIFIER__ __INT64_FMT_MODIFIER__ 30 31 // The *-elf and arm-eabi GCC targets use 'int' for the fast{8,16,32} 32 // types. On LP64 systems, 'long' is used for the fast64 type, and 33 // 'long long' on non-LP64 systems. 34 #define __INT_FAST8_FMT_MODIFIER__ "" 35 #define __INT_FAST16_FMT_MODIFIER__ "" 36 #define __INT_FAST32_FMT_MODIFIER__ "" 37 #if _LP64 38 #define __INT_FAST64_FMT_MODIFIER__ "l" 39 #else 40 #define __INT_FAST64_FMT_MODIFIER__ "ll" 41 #endif 42 43 // On machines where 'long' types are 64 bits, the compiler defines 44 // __INT64_TYPE__ et al using 'long', not 'long long', though both are 45 // 64-bit types. 46 #ifdef _LP64 47 #define __INT64_FMT_MODIFIER__ "l" 48 #define __INTPTR_FMT_MODIFIER__ "l" 49 #else 50 #define __INT64_FMT_MODIFIER__ "ll" 51 #define __INTPTR_FMT_MODIFIER__ "" 52 #endif 53 54 #define __INTMAX_FMT_MODIFIER__ __INT64_FMT_MODIFIER__ 55 56 #define __INTMAX_FMTd__ __INTMAX_FMT_MODIFIER__ "d" 57 #define __INTMAX_FMTi__ __INTMAX_FMT_MODIFIER__ "i" 58 #define __UINTMAX_FMTo__ __INTMAX_FMT_MODIFIER__ "o" 59 #define __UINTMAX_FMTu__ __INTMAX_FMT_MODIFIER__ "u" 60 #define __UINTMAX_FMTx__ __INTMAX_FMT_MODIFIER__ "x" 61 #define __UINTMAX_FMTX__ __INTMAX_FMT_MODIFIER__ "X" 62 #define __INTPTR_FMTd__ __INTPTR_FMT_MODIFIER__ "d" 63 #define __INTPTR_FMTi__ __INTPTR_FMT_MODIFIER__ "i" 64 #define __UINTPTR_FMTo__ __INTPTR_FMT_MODIFIER__ "o" 65 #define __UINTPTR_FMTu__ __INTPTR_FMT_MODIFIER__ "u" 66 #define __UINTPTR_FMTx__ __INTPTR_FMT_MODIFIER__ "x" 67 #define __UINTPTR_FMTX__ __INTPTR_FMT_MODIFIER__ "X" 68 #define __INT8_FMTd__ __INT8_FMT_MODIFIER__ "d" 69 #define __INT8_FMTi__ __INT8_FMT_MODIFIER__ "i" 70 #define __INT16_FMTd__ __INT16_FMT_MODIFIER__ "d" 71 #define __INT16_FMTi__ __INT16_FMT_MODIFIER__ "i" 72 #define __INT32_FMTd__ __INT32_FMT_MODIFIER__ "d" 73 #define __INT32_FMTi__ __INT32_FMT_MODIFIER__ "i" 74 #define __INT64_FMTd__ __INT64_FMT_MODIFIER__ "d" 75 #define __INT64_FMTi__ __INT64_FMT_MODIFIER__ "i" 76 #define __UINT8_FMTo__ __INT8_FMT_MODIFIER__ "o" 77 #define __UINT8_FMTu__ __INT8_FMT_MODIFIER__ "u" 78 #define __UINT8_FMTx__ __INT8_FMT_MODIFIER__ "x" 79 #define __UINT8_FMTX__ __INT8_FMT_MODIFIER__ "X" 80 #define __UINT16_FMTo__ __INT16_FMT_MODIFIER__ "o" 81 #define __UINT16_FMTu__ __INT16_FMT_MODIFIER__ "u" 82 #define __UINT16_FMTx__ __INT16_FMT_MODIFIER__ "x" 83 #define __UINT16_FMTX__ __INT16_FMT_MODIFIER__ "X" 84 #define __UINT32_FMTo__ __INT32_FMT_MODIFIER__ "o" 85 #define __UINT32_FMTu__ __INT32_FMT_MODIFIER__ "u" 86 #define __UINT32_FMTx__ __INT32_FMT_MODIFIER__ "x" 87 #define __UINT32_FMTX__ __INT32_FMT_MODIFIER__ "X" 88 #define __UINT64_FMTo__ __INT64_FMT_MODIFIER__ "o" 89 #define __UINT64_FMTu__ __INT64_FMT_MODIFIER__ "u" 90 #define __UINT64_FMTx__ __INT64_FMT_MODIFIER__ "x" 91 #define __UINT64_FMTX__ __INT64_FMT_MODIFIER__ "X" 92 #define __INT_LEAST8_FMTd__ __INT_LEAST8_FMT_MODIFIER__ "d" 93 #define __INT_LEAST8_FMTi__ __INT_LEAST8_FMT_MODIFIER__ "i" 94 #define __UINT_LEAST8_FMTo__ __INT_LEAST8_FMT_MODIFIER__ "o" 95 #define __UINT_LEAST8_FMTu__ __INT_LEAST8_FMT_MODIFIER__ "u" 96 #define __UINT_LEAST8_FMTx__ __INT_LEAST8_FMT_MODIFIER__ "x" 97 #define __UINT_LEAST8_FMTX__ __INT_LEAST8_FMT_MODIFIER__ "X" 98 #define __INT_LEAST16_FMTd__ __INT_LEAST16_FMT_MODIFIER__ "d" 99 #define __INT_LEAST16_FMTi__ __INT_LEAST16_FMT_MODIFIER__ "i" 100 #define __UINT_LEAST16_FMTo__ __INT_LEAST16_FMT_MODIFIER__ "o" 101 #define __UINT_LEAST16_FMTu__ __INT_LEAST16_FMT_MODIFIER__ "u" 102 #define __UINT_LEAST16_FMTx__ __INT_LEAST16_FMT_MODIFIER__ "x" 103 #define __UINT_LEAST16_FMTX__ __INT_LEAST16_FMT_MODIFIER__ "X" 104 #define __INT_LEAST32_FMTd__ __INT_LEAST32_FMT_MODIFIER__ "d" 105 #define __INT_LEAST32_FMTi__ __INT_LEAST32_FMT_MODIFIER__ "i" 106 #define __UINT_LEAST32_FMTo__ __INT_LEAST32_FMT_MODIFIER__ "o" 107 #define __UINT_LEAST32_FMTu__ __INT_LEAST32_FMT_MODIFIER__ "u" 108 #define __UINT_LEAST32_FMTx__ __INT_LEAST32_FMT_MODIFIER__ "x" 109 #define __UINT_LEAST32_FMTX__ __INT_LEAST32_FMT_MODIFIER__ "X" 110 #define __INT_LEAST64_FMTd__ __INT_LEAST64_FMT_MODIFIER__ "d" 111 #define __INT_LEAST64_FMTi__ __INT_LEAST64_FMT_MODIFIER__ "i" 112 #define __UINT_LEAST64_FMTo__ __INT_LEAST64_FMT_MODIFIER__ "o" 113 #define __UINT_LEAST64_FMTu__ __INT_LEAST64_FMT_MODIFIER__ "u" 114 #define __UINT_LEAST64_FMTx__ __INT_LEAST64_FMT_MODIFIER__ "x" 115 #define __UINT_LEAST64_FMTX__ __INT_LEAST64_FMT_MODIFIER__ "X" 116 #define __INT_FAST8_FMTd__ __INT_FAST8_FMT_MODIFIER__ "d" 117 #define __INT_FAST8_FMTi__ __INT_FAST8_FMT_MODIFIER__ "i" 118 #define __UINT_FAST8_FMTo__ __INT_FAST8_FMT_MODIFIER__ "o" 119 #define __UINT_FAST8_FMTu__ __INT_FAST8_FMT_MODIFIER__ "u" 120 #define __UINT_FAST8_FMTx__ __INT_FAST8_FMT_MODIFIER__ "x" 121 #define __UINT_FAST8_FMTX__ __INT_FAST8_FMT_MODIFIER__ "X" 122 #define __INT_FAST16_FMTd__ __INT_FAST16_FMT_MODIFIER__ "d" 123 #define __INT_FAST16_FMTi__ __INT_FAST16_FMT_MODIFIER__ "i" 124 #define __UINT_FAST16_FMTo__ __INT_FAST16_FMT_MODIFIER__ "o" 125 #define __UINT_FAST16_FMTu__ __INT_FAST16_FMT_MODIFIER__ "u" 126 #define __UINT_FAST16_FMTx__ __INT_FAST16_FMT_MODIFIER__ "x" 127 #define __UINT_FAST16_FMTX__ __INT_FAST16_FMT_MODIFIER__ "X" 128 #define __INT_FAST32_FMTd__ __INT_FAST32_FMT_MODIFIER__ "d" 129 #define __INT_FAST32_FMTi__ __INT_FAST32_FMT_MODIFIER__ "i" 130 #define __UINT_FAST32_FMTo__ __INT_FAST32_FMT_MODIFIER__ "o" 131 #define __UINT_FAST32_FMTu__ __INT_FAST32_FMT_MODIFIER__ "u" 132 #define __UINT_FAST32_FMTx__ __INT_FAST32_FMT_MODIFIER__ "x" 133 #define __UINT_FAST32_FMTX__ __INT_FAST32_FMT_MODIFIER__ "X" 134 #define __INT_FAST64_FMTd__ __INT_FAST64_FMT_MODIFIER__ "d" 135 #define __INT_FAST64_FMTi__ __INT_FAST64_FMT_MODIFIER__ "i" 136 #define __UINT_FAST64_FMTo__ __INT_FAST64_FMT_MODIFIER__ "o" 137 #define __UINT_FAST64_FMTu__ __INT_FAST64_FMT_MODIFIER__ "u" 138 #define __UINT_FAST64_FMTx__ __INT_FAST64_FMT_MODIFIER__ "x" 139 #define __UINT_FAST64_FMTX__ __INT_FAST64_FMT_MODIFIER__ "X" 140 141 #endif 142 143 typedef __UINT8_TYPE__ uint8_t; 144 typedef __UINT16_TYPE__ uint16_t; 145 typedef __UINT32_TYPE__ uint32_t; 146 typedef __UINT64_TYPE__ uint64_t; 147 typedef __INT8_TYPE__ int8_t; 148 typedef __INT16_TYPE__ int16_t; 149 typedef __INT32_TYPE__ int32_t; 150 typedef __INT64_TYPE__ int64_t; 151 152 #define UINT8_MAX __UINT8_MAX__ 153 #define UINT16_MAX __UINT16_MAX__ 154 #define UINT32_MAX __UINT32_MAX__ 155 #define UINT64_MAX __UINT64_MAX__ 156 157 #define INT8_MAX __INT8_MAX__ 158 #define INT16_MAX __INT16_MAX__ 159 #define INT32_MAX __INT32_MAX__ 160 #define INT64_MAX __INT64_MAX__ 161 162 #define INT8_MIN (-INT8_MAX - 1) 163 #define INT16_MIN (-INT16_MAX - 1) 164 #define INT32_MIN (-INT32_MAX - 1) 165 #define INT64_MIN (-INT64_MAX - 1) 166 167 typedef __UINT_LEAST8_TYPE__ uint_least8_t; 168 typedef __UINT_LEAST16_TYPE__ uint_least16_t; 169 typedef __UINT_LEAST32_TYPE__ uint_least32_t; 170 typedef __UINT_LEAST64_TYPE__ uint_least64_t; 171 typedef __INT_LEAST8_TYPE__ int_least8_t; 172 typedef __INT_LEAST16_TYPE__ int_least16_t; 173 typedef __INT_LEAST32_TYPE__ int_least32_t; 174 typedef __INT_LEAST64_TYPE__ int_least64_t; 175 176 #define UINT_LEAST8_MAX __UINT_LEAST8_MAX__ 177 #define UINT_LEAST16_MAX __UINT_LEAST16_MAX__ 178 #define UINT_LEAST32_MAX __UINT_LEAST32_MAX__ 179 #define UINT_LEAST64_MAX __UINT_LEAST64_MAX__ 180 181 #define INT_LEAST8_MAX __INT_LEAST8_MAX__ 182 #define INT_LEAST16_MAX __INT_LEAST16_MAX__ 183 #define INT_LEAST32_MAX __INT_LEAST32_MAX__ 184 #define INT_LEAST64_MAX __INT_LEAST64_MAX__ 185 186 #define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1) 187 #define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1) 188 #define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1) 189 #define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1) 190 191 typedef __UINT_FAST8_TYPE__ uint_fast8_t; 192 typedef __UINT_FAST16_TYPE__ uint_fast16_t; 193 typedef __UINT_FAST32_TYPE__ uint_fast32_t; 194 typedef __UINT_FAST64_TYPE__ uint_fast64_t; 195 typedef __INT_FAST8_TYPE__ int_fast8_t; 196 typedef __INT_FAST16_TYPE__ int_fast16_t; 197 typedef __INT_FAST32_TYPE__ int_fast32_t; 198 typedef __INT_FAST64_TYPE__ int_fast64_t; 199 200 #define UINT_FAST8_MAX __UINT_FAST8_MAX__ 201 #define UINT_FAST16_MAX __UINT_FAST16_MAX__ 202 #define UINT_FAST32_MAX __UINT_FAST32_MAX__ 203 #define UINT_FAST64_MAX __UINT_FAST64_MAX__ 204 205 #define INT_FAST8_MAX __INT_FAST8_MAX__ 206 #define INT_FAST16_MAX __INT_FAST16_MAX__ 207 #define INT_FAST32_MAX __INT_FAST32_MAX__ 208 #define INT_FAST64_MAX __INT_FAST64_MAX__ 209 210 #define INT_FAST8_MIN (-INT_FAST8_MAX - 1) 211 #define INT_FAST16_MIN (-INT_FAST16_MAX - 1) 212 #define INT_FAST32_MIN (-INT_FAST32_MAX - 1) 213 #define INT_FAST64_MIN (-INT_FAST64_MAX - 1) 214 215 typedef __INTPTR_TYPE__ intptr_t; 216 typedef __UINTPTR_TYPE__ uintptr_t; 217 218 #define INTPTR_MAX __INTPTR_MAX__ 219 #define INTPTR_MIN (-INTPTR_MAX - 1) 220 #define UINTPTR_MAX __UINTPTR_MAX__ 221 222 typedef __INTMAX_TYPE__ intmax_t; 223 typedef __UINTMAX_TYPE__ uintmax_t; 224 225 #define INTMAX_MAX __INTMAX_MAX__ 226 #define INTMAX_MIN (-INTMAX_MAX - 1) 227 #define UINTMAX_MAX __UINTMAX_MAX__ 228 229 #define SIZE_MAX __SIZE_MAX__ 230 231 // GCC defines __<type>INT<size>_C macros which append the correct suffix 232 // to an (un)signed integer literal, with <size> being one of 8, 16, 32, 64 233 // and MAX, and type being U for unsigned types. The standard stdint.h macros 234 // with the same names without the leading __ could be implemented in terms of 235 // these macros. 236 // 237 // Clang predefines macros __<type>INT<size>_C_SUFFIX__ which expand to the 238 // suffix itself. We define the standard stdint.h macros in terms of the GCC 239 // variants and for Clang we define their equivalents. 240 #ifndef __INTMAX_C 241 242 #define __int_c_join(a, b) a ## b 243 #define __int_c(v, suffix) __int_c_join(v, suffix) 244 245 #define __INT8_C(c) __int_c(c, __INT8_C_SUFFIX__) 246 #define __INT16_C(c) __int_c(c, __INT16_C_SUFFIX__) 247 #define __INT32_C(c) __int_c(c, __INT32_C_SUFFIX__) 248 #define __INT64_C(c) __int_c(c, __INT64_C_SUFFIX__) 249 250 #define __UINT8_C(c) __int_c(c, __UINT8_C_SUFFIX__) 251 #define __UINT16_C(c) __int_c(c, __UINT16_C_SUFFIX__) 252 #define __UINT32_C(c) __int_c(c, __UINT32_C_SUFFIX__) 253 #define __UINT64_C(c) __int_c(c, __UINT64_C_SUFFIX__) 254 255 #define __INTMAX_C(c) __int_c(c, __INTMAX_C_SUFFIX__) 256 #define __UINTMAX_C(c) __int_c(c, __UINTMAX_C_SUFFIX__) 257 258 #endif 259 260 #define INT8_C(c) __INT8_C(c) 261 #define INT16_C(c) __INT16_C(c) 262 #define INT32_C(c) __INT32_C(c) 263 #define INT64_C(c) __INT64_C(c) 264 265 #define UINT8_C(c) __UINT8_C(c) 266 #define UINT16_C(c) __UINT16_C(c) 267 #define UINT32_C(c) __UINT32_C(c) 268 #define UINT64_C(c) __UINT64_C(c) 269 270 #define INTMAX_C(c) __INTMAX_C(c) 271 #define UINTMAX_C(c) __UINTMAX_C(c) 272