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