stdint.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*===---- stdint.h - Standard header for sized integer types --------------===*\
  2. *
  3. * Copyright (c) 2009 Chris Lattner
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. *
  23. \*===----------------------------------------------------------------------===*/
  24. /* If we're hosted, fall back to the system's stdint.h, which might have
  25. * additional definitions.
  26. */
  27. #if __STDC_HOSTED__ && __has_include_next(<stdint.h>)
  28. // C99 7.18.3 Limits of other integer types
  29. //
  30. // Footnote 219, 220: C++ implementations should define these macros only when
  31. // __STDC_LIMIT_MACROS is defined before <stdint.h> is included.
  32. //
  33. // Footnote 222: C++ implementations should define these macros only when
  34. // __STDC_CONSTANT_MACROS is defined before <stdint.h> is included.
  35. //
  36. // C++11 [cstdint.syn]p2:
  37. //
  38. // The macros defined by <cstdint> are provided unconditionally. In particular,
  39. // the symbols __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS (mentioned in
  40. // footnotes 219, 220, and 222 in the C standard) play no role in C++.
  41. //
  42. // C11 removed the problematic footnotes.
  43. //
  44. // Work around this inconsistency by always defining those macros in C++ mode,
  45. // so that a C library implementation which follows the C99 standard can be
  46. // used in C++.
  47. # ifdef __cplusplus
  48. # if !defined(__STDC_LIMIT_MACROS)
  49. # define __STDC_LIMIT_MACROS
  50. # define __STDC_LIMIT_MACROS_DEFINED_BY_CLANG
  51. # endif
  52. # if !defined(__STDC_CONSTANT_MACROS)
  53. # define __STDC_CONSTANT_MACROS
  54. # define __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG
  55. # endif
  56. # endif
  57. # include_next <stdint.h>
  58. # ifdef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG
  59. # undef __STDC_LIMIT_MACROS
  60. # undef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG
  61. # endif
  62. # ifdef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG
  63. # undef __STDC_CONSTANT_MACROS
  64. # undef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG
  65. # endif
  66. #else
  67. #ifndef __CLANG_STDINT_H
  68. #define __CLANG_STDINT_H
  69. /* C99 7.18.1.1 Exact-width integer types.
  70. * C99 7.18.1.2 Minimum-width integer types.
  71. * C99 7.18.1.3 Fastest minimum-width integer types.
  72. *
  73. * The standard requires that exact-width type be defined for 8-, 16-, 32-, and
  74. * 64-bit types if they are implemented. Other exact width types are optional.
  75. * This implementation defines an exact-width types for every integer width
  76. * that is represented in the standard integer types.
  77. *
  78. * The standard also requires minimum-width types be defined for 8-, 16-, 32-,
  79. * and 64-bit widths regardless of whether there are corresponding exact-width
  80. * types.
  81. *
  82. * To accommodate targets that are missing types that are exactly 8, 16, 32, or
  83. * 64 bits wide, this implementation takes an approach of cascading
  84. * redefintions, redefining __int_leastN_t to successively smaller exact-width
  85. * types. It is therefore important that the types are defined in order of
  86. * descending widths.
  87. *
  88. * We currently assume that the minimum-width types and the fastest
  89. * minimum-width types are the same. This is allowed by the standard, but is
  90. * suboptimal.
  91. *
  92. * In violation of the standard, some targets do not implement a type that is
  93. * wide enough to represent all of the required widths (8-, 16-, 32-, 64-bit).
  94. * To accommodate these targets, a required minimum-width type is only
  95. * defined if there exists an exact-width type of equal or greater width.
  96. */
  97. #ifdef __INT64_TYPE__
  98. # ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/
  99. typedef __INT64_TYPE__ int64_t;
  100. # endif /* __int8_t_defined */
  101. typedef __UINT64_TYPE__ uint64_t;
  102. # define __int_least64_t int64_t
  103. # define __uint_least64_t uint64_t
  104. # define __int_least32_t int64_t
  105. # define __uint_least32_t uint64_t
  106. # define __int_least16_t int64_t
  107. # define __uint_least16_t uint64_t
  108. # define __int_least8_t int64_t
  109. # define __uint_least8_t uint64_t
  110. #endif /* __INT64_TYPE__ */
  111. #ifdef __int_least64_t
  112. typedef __int_least64_t int_least64_t;
  113. typedef __uint_least64_t uint_least64_t;
  114. typedef __int_least64_t int_fast64_t;
  115. typedef __uint_least64_t uint_fast64_t;
  116. #endif /* __int_least64_t */
  117. #ifdef __INT56_TYPE__
  118. typedef __INT56_TYPE__ int56_t;
  119. typedef __UINT56_TYPE__ uint56_t;
  120. typedef int56_t int_least56_t;
  121. typedef uint56_t uint_least56_t;
  122. typedef int56_t int_fast56_t;
  123. typedef uint56_t uint_fast56_t;
  124. # define __int_least32_t int56_t
  125. # define __uint_least32_t uint56_t
  126. # define __int_least16_t int56_t
  127. # define __uint_least16_t uint56_t
  128. # define __int_least8_t int56_t
  129. # define __uint_least8_t uint56_t
  130. #endif /* __INT56_TYPE__ */
  131. #ifdef __INT48_TYPE__
  132. typedef __INT48_TYPE__ int48_t;
  133. typedef __UINT48_TYPE__ uint48_t;
  134. typedef int48_t int_least48_t;
  135. typedef uint48_t uint_least48_t;
  136. typedef int48_t int_fast48_t;
  137. typedef uint48_t uint_fast48_t;
  138. # define __int_least32_t int48_t
  139. # define __uint_least32_t uint48_t
  140. # define __int_least16_t int48_t
  141. # define __uint_least16_t uint48_t
  142. # define __int_least8_t int48_t
  143. # define __uint_least8_t uint48_t
  144. #endif /* __INT48_TYPE__ */
  145. #ifdef __INT40_TYPE__
  146. typedef __INT40_TYPE__ int40_t;
  147. typedef __UINT40_TYPE__ uint40_t;
  148. typedef int40_t int_least40_t;
  149. typedef uint40_t uint_least40_t;
  150. typedef int40_t int_fast40_t;
  151. typedef uint40_t uint_fast40_t;
  152. # define __int_least32_t int40_t
  153. # define __uint_least32_t uint40_t
  154. # define __int_least16_t int40_t
  155. # define __uint_least16_t uint40_t
  156. # define __int_least8_t int40_t
  157. # define __uint_least8_t uint40_t
  158. #endif /* __INT40_TYPE__ */
  159. #ifdef __INT32_TYPE__
  160. # ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/
  161. typedef __INT32_TYPE__ int32_t;
  162. # endif /* __int8_t_defined */
  163. # ifndef __uint32_t_defined /* more glibc compatibility */
  164. # define __uint32_t_defined
  165. typedef __UINT32_TYPE__ uint32_t;
  166. # endif /* __uint32_t_defined */
  167. # define __int_least32_t int32_t
  168. # define __uint_least32_t uint32_t
  169. # define __int_least16_t int32_t
  170. # define __uint_least16_t uint32_t
  171. # define __int_least8_t int32_t
  172. # define __uint_least8_t uint32_t
  173. #endif /* __INT32_TYPE__ */
  174. #ifdef __int_least32_t
  175. typedef __int_least32_t int_least32_t;
  176. typedef __uint_least32_t uint_least32_t;
  177. typedef __int_least32_t int_fast32_t;
  178. typedef __uint_least32_t uint_fast32_t;
  179. #endif /* __int_least32_t */
  180. #ifdef __INT24_TYPE__
  181. typedef __INT24_TYPE__ int24_t;
  182. typedef __UINT24_TYPE__ uint24_t;
  183. typedef int24_t int_least24_t;
  184. typedef uint24_t uint_least24_t;
  185. typedef int24_t int_fast24_t;
  186. typedef uint24_t uint_fast24_t;
  187. # define __int_least16_t int24_t
  188. # define __uint_least16_t uint24_t
  189. # define __int_least8_t int24_t
  190. # define __uint_least8_t uint24_t
  191. #endif /* __INT24_TYPE__ */
  192. #ifdef __INT16_TYPE__
  193. #ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/
  194. typedef __INT16_TYPE__ int16_t;
  195. #endif /* __int8_t_defined */
  196. typedef __UINT16_TYPE__ uint16_t;
  197. # define __int_least16_t int16_t
  198. # define __uint_least16_t uint16_t
  199. # define __int_least8_t int16_t
  200. # define __uint_least8_t uint16_t
  201. #endif /* __INT16_TYPE__ */
  202. #ifdef __int_least16_t
  203. typedef __int_least16_t int_least16_t;
  204. typedef __uint_least16_t uint_least16_t;
  205. typedef __int_least16_t int_fast16_t;
  206. typedef __uint_least16_t uint_fast16_t;
  207. #endif /* __int_least16_t */
  208. #ifdef __INT8_TYPE__
  209. #ifndef __int8_t_defined /* glibc sys/types.h also defines int8_t*/
  210. typedef __INT8_TYPE__ int8_t;
  211. #endif /* __int8_t_defined */
  212. typedef __UINT8_TYPE__ uint8_t;
  213. # define __int_least8_t int8_t
  214. # define __uint_least8_t uint8_t
  215. #endif /* __INT8_TYPE__ */
  216. #ifdef __int_least8_t
  217. typedef __int_least8_t int_least8_t;
  218. typedef __uint_least8_t uint_least8_t;
  219. typedef __int_least8_t int_fast8_t;
  220. typedef __uint_least8_t uint_fast8_t;
  221. #endif /* __int_least8_t */
  222. /* prevent glibc sys/types.h from defining conflicting types */
  223. #ifndef __int8_t_defined
  224. # define __int8_t_defined
  225. #endif /* __int8_t_defined */
  226. /* C99 7.18.1.4 Integer types capable of holding object pointers.
  227. */
  228. #define __stdint_join3(a,b,c) a ## b ## c
  229. #ifndef _INTPTR_T
  230. #ifndef __intptr_t_defined
  231. typedef __INTPTR_TYPE__ intptr_t;
  232. #define __intptr_t_defined
  233. #define _INTPTR_T
  234. #endif
  235. #endif
  236. #ifndef _UINTPTR_T
  237. typedef __UINTPTR_TYPE__ uintptr_t;
  238. #define _UINTPTR_T
  239. #endif
  240. /* C99 7.18.1.5 Greatest-width integer types.
  241. */
  242. typedef __INTMAX_TYPE__ intmax_t;
  243. typedef __UINTMAX_TYPE__ uintmax_t;
  244. /* C99 7.18.4 Macros for minimum-width integer constants.
  245. *
  246. * The standard requires that integer constant macros be defined for all the
  247. * minimum-width types defined above. As 8-, 16-, 32-, and 64-bit minimum-width
  248. * types are required, the corresponding integer constant macros are defined
  249. * here. This implementation also defines minimum-width types for every other
  250. * integer width that the target implements, so corresponding macros are
  251. * defined below, too.
  252. *
  253. * These macros are defined using the same successive-shrinking approach as
  254. * the type definitions above. It is likewise important that macros are defined
  255. * in order of decending width.
  256. *
  257. * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the
  258. * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
  259. */
  260. #define __int_c_join(a, b) a ## b
  261. #define __int_c(v, suffix) __int_c_join(v, suffix)
  262. #define __uint_c(v, suffix) __int_c_join(v##U, suffix)
  263. #ifdef __INT64_TYPE__
  264. # ifdef __INT64_C_SUFFIX__
  265. # define __int64_c_suffix __INT64_C_SUFFIX__
  266. # define __int32_c_suffix __INT64_C_SUFFIX__
  267. # define __int16_c_suffix __INT64_C_SUFFIX__
  268. # define __int8_c_suffix __INT64_C_SUFFIX__
  269. # else
  270. # undef __int64_c_suffix
  271. # undef __int32_c_suffix
  272. # undef __int16_c_suffix
  273. # undef __int8_c_suffix
  274. # endif /* __INT64_C_SUFFIX__ */
  275. #endif /* __INT64_TYPE__ */
  276. #ifdef __int_least64_t
  277. # ifdef __int64_c_suffix
  278. # define INT64_C(v) __int_c(v, __int64_c_suffix)
  279. # define UINT64_C(v) __uint_c(v, __int64_c_suffix)
  280. # else
  281. # define INT64_C(v) v
  282. # define UINT64_C(v) v ## U
  283. # endif /* __int64_c_suffix */
  284. #endif /* __int_least64_t */
  285. #ifdef __INT56_TYPE__
  286. # ifdef __INT56_C_SUFFIX__
  287. # define INT56_C(v) __int_c(v, __INT56_C_SUFFIX__)
  288. # define UINT56_C(v) __uint_c(v, __INT56_C_SUFFIX__)
  289. # define __int32_c_suffix __INT56_C_SUFFIX__
  290. # define __int16_c_suffix __INT56_C_SUFFIX__
  291. # define __int8_c_suffix __INT56_C_SUFFIX__
  292. # else
  293. # define INT56_C(v) v
  294. # define UINT56_C(v) v ## U
  295. # undef __int32_c_suffix
  296. # undef __int16_c_suffix
  297. # undef __int8_c_suffix
  298. # endif /* __INT56_C_SUFFIX__ */
  299. #endif /* __INT56_TYPE__ */
  300. #ifdef __INT48_TYPE__
  301. # ifdef __INT48_C_SUFFIX__
  302. # define INT48_C(v) __int_c(v, __INT48_C_SUFFIX__)
  303. # define UINT48_C(v) __uint_c(v, __INT48_C_SUFFIX__)
  304. # define __int32_c_suffix __INT48_C_SUFFIX__
  305. # define __int16_c_suffix __INT48_C_SUFFIX__
  306. # define __int8_c_suffix __INT48_C_SUFFIX__
  307. # else
  308. # define INT48_C(v) v
  309. # define UINT48_C(v) v ## U
  310. # undef __int32_c_suffix
  311. # undef __int16_c_suffix
  312. # undef __int8_c_suffix
  313. # endif /* __INT48_C_SUFFIX__ */
  314. #endif /* __INT48_TYPE__ */
  315. #ifdef __INT40_TYPE__
  316. # ifdef __INT40_C_SUFFIX__
  317. # define INT40_C(v) __int_c(v, __INT40_C_SUFFIX__)
  318. # define UINT40_C(v) __uint_c(v, __INT40_C_SUFFIX__)
  319. # define __int32_c_suffix __INT40_C_SUFFIX__
  320. # define __int16_c_suffix __INT40_C_SUFFIX__
  321. # define __int8_c_suffix __INT40_C_SUFFIX__
  322. # else
  323. # define INT40_C(v) v
  324. # define UINT40_C(v) v ## U
  325. # undef __int32_c_suffix
  326. # undef __int16_c_suffix
  327. # undef __int8_c_suffix
  328. # endif /* __INT40_C_SUFFIX__ */
  329. #endif /* __INT40_TYPE__ */
  330. #ifdef __INT32_TYPE__
  331. # ifdef __INT32_C_SUFFIX__
  332. # define __int32_c_suffix __INT32_C_SUFFIX__
  333. # define __int16_c_suffix __INT32_C_SUFFIX__
  334. # define __int8_c_suffix __INT32_C_SUFFIX__
  335. #else
  336. # undef __int32_c_suffix
  337. # undef __int16_c_suffix
  338. # undef __int8_c_suffix
  339. # endif /* __INT32_C_SUFFIX__ */
  340. #endif /* __INT32_TYPE__ */
  341. #ifdef __int_least32_t
  342. # ifdef __int32_c_suffix
  343. # define INT32_C(v) __int_c(v, __int32_c_suffix)
  344. # define UINT32_C(v) __uint_c(v, __int32_c_suffix)
  345. # else
  346. # define INT32_C(v) v
  347. # define UINT32_C(v) v ## U
  348. # endif /* __int32_c_suffix */
  349. #endif /* __int_least32_t */
  350. #ifdef __INT24_TYPE__
  351. # ifdef __INT24_C_SUFFIX__
  352. # define INT24_C(v) __int_c(v, __INT24_C_SUFFIX__)
  353. # define UINT24_C(v) __uint_c(v, __INT24_C_SUFFIX__)
  354. # define __int16_c_suffix __INT24_C_SUFFIX__
  355. # define __int8_c_suffix __INT24_C_SUFFIX__
  356. # else
  357. # define INT24_C(v) v
  358. # define UINT24_C(v) v ## U
  359. # undef __int16_c_suffix
  360. # undef __int8_c_suffix
  361. # endif /* __INT24_C_SUFFIX__ */
  362. #endif /* __INT24_TYPE__ */
  363. #ifdef __INT16_TYPE__
  364. # ifdef __INT16_C_SUFFIX__
  365. # define __int16_c_suffix __INT16_C_SUFFIX__
  366. # define __int8_c_suffix __INT16_C_SUFFIX__
  367. #else
  368. # undef __int16_c_suffix
  369. # undef __int8_c_suffix
  370. # endif /* __INT16_C_SUFFIX__ */
  371. #endif /* __INT16_TYPE__ */
  372. #ifdef __int_least16_t
  373. # ifdef __int16_c_suffix
  374. # define INT16_C(v) __int_c(v, __int16_c_suffix)
  375. # define UINT16_C(v) __uint_c(v, __int16_c_suffix)
  376. # else
  377. # define INT16_C(v) v
  378. # define UINT16_C(v) v ## U
  379. # endif /* __int16_c_suffix */
  380. #endif /* __int_least16_t */
  381. #ifdef __INT8_TYPE__
  382. # ifdef __INT8_C_SUFFIX__
  383. # define __int8_c_suffix __INT8_C_SUFFIX__
  384. #else
  385. # undef __int8_c_suffix
  386. # endif /* __INT8_C_SUFFIX__ */
  387. #endif /* __INT8_TYPE__ */
  388. #ifdef __int_least8_t
  389. # ifdef __int8_c_suffix
  390. # define INT8_C(v) __int_c(v, __int8_c_suffix)
  391. # define UINT8_C(v) __uint_c(v, __int8_c_suffix)
  392. # else
  393. # define INT8_C(v) v
  394. # define UINT8_C(v) v ## U
  395. # endif /* __int8_c_suffix */
  396. #endif /* __int_least8_t */
  397. /* C99 7.18.2.1 Limits of exact-width integer types.
  398. * C99 7.18.2.2 Limits of minimum-width integer types.
  399. * C99 7.18.2.3 Limits of fastest minimum-width integer types.
  400. *
  401. * The presence of limit macros are completely optional in C99. This
  402. * implementation defines limits for all of the types (exact- and
  403. * minimum-width) that it defines above, using the limits of the minimum-width
  404. * type for any types that do not have exact-width representations.
  405. *
  406. * As in the type definitions, this section takes an approach of
  407. * successive-shrinking to determine which limits to use for the standard (8,
  408. * 16, 32, 64) bit widths when they don't have exact representations. It is
  409. * therefore important that the defintions be kept in order of decending
  410. * widths.
  411. *
  412. * Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the
  413. * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
  414. */
  415. #ifdef __INT64_TYPE__
  416. # define INT64_MAX INT64_C( 9223372036854775807)
  417. # define INT64_MIN (-INT64_C( 9223372036854775807)-1)
  418. # define UINT64_MAX UINT64_C(18446744073709551615)
  419. # define __INT_LEAST64_MIN INT64_MIN
  420. # define __INT_LEAST64_MAX INT64_MAX
  421. # define __UINT_LEAST64_MAX UINT64_MAX
  422. # define __INT_LEAST32_MIN INT64_MIN
  423. # define __INT_LEAST32_MAX INT64_MAX
  424. # define __UINT_LEAST32_MAX UINT64_MAX
  425. # define __INT_LEAST16_MIN INT64_MIN
  426. # define __INT_LEAST16_MAX INT64_MAX
  427. # define __UINT_LEAST16_MAX UINT64_MAX
  428. # define __INT_LEAST8_MIN INT64_MIN
  429. # define __INT_LEAST8_MAX INT64_MAX
  430. # define __UINT_LEAST8_MAX UINT64_MAX
  431. #endif /* __INT64_TYPE__ */
  432. #ifdef __INT_LEAST64_MIN
  433. # define INT_LEAST64_MIN __INT_LEAST64_MIN
  434. # define INT_LEAST64_MAX __INT_LEAST64_MAX
  435. # define UINT_LEAST64_MAX __UINT_LEAST64_MAX
  436. # define INT_FAST64_MIN __INT_LEAST64_MIN
  437. # define INT_FAST64_MAX __INT_LEAST64_MAX
  438. # define UINT_FAST64_MAX __UINT_LEAST64_MAX
  439. #endif /* __INT_LEAST64_MIN */
  440. #ifdef __INT56_TYPE__
  441. # define INT56_MAX INT56_C(36028797018963967)
  442. # define INT56_MIN (-INT56_C(36028797018963967)-1)
  443. # define UINT56_MAX UINT56_C(72057594037927935)
  444. # define INT_LEAST56_MIN INT56_MIN
  445. # define INT_LEAST56_MAX INT56_MAX
  446. # define UINT_LEAST56_MAX UINT56_MAX
  447. # define INT_FAST56_MIN INT56_MIN
  448. # define INT_FAST56_MAX INT56_MAX
  449. # define UINT_FAST56_MAX UINT56_MAX
  450. # define __INT_LEAST32_MIN INT56_MIN
  451. # define __INT_LEAST32_MAX INT56_MAX
  452. # define __UINT_LEAST32_MAX UINT56_MAX
  453. # define __INT_LEAST16_MIN INT56_MIN
  454. # define __INT_LEAST16_MAX INT56_MAX
  455. # define __UINT_LEAST16_MAX UINT56_MAX
  456. # define __INT_LEAST8_MIN INT56_MIN
  457. # define __INT_LEAST8_MAX INT56_MAX
  458. # define __UINT_LEAST8_MAX UINT56_MAX
  459. #endif /* __INT56_TYPE__ */
  460. #ifdef __INT48_TYPE__
  461. # define INT48_MAX INT48_C(140737488355327)
  462. # define INT48_MIN (-INT48_C(140737488355327)-1)
  463. # define UINT48_MAX UINT48_C(281474976710655)
  464. # define INT_LEAST48_MIN INT48_MIN
  465. # define INT_LEAST48_MAX INT48_MAX
  466. # define UINT_LEAST48_MAX UINT48_MAX
  467. # define INT_FAST48_MIN INT48_MIN
  468. # define INT_FAST48_MAX INT48_MAX
  469. # define UINT_FAST48_MAX UINT48_MAX
  470. # define __INT_LEAST32_MIN INT48_MIN
  471. # define __INT_LEAST32_MAX INT48_MAX
  472. # define __UINT_LEAST32_MAX UINT48_MAX
  473. # define __INT_LEAST16_MIN INT48_MIN
  474. # define __INT_LEAST16_MAX INT48_MAX
  475. # define __UINT_LEAST16_MAX UINT48_MAX
  476. # define __INT_LEAST8_MIN INT48_MIN
  477. # define __INT_LEAST8_MAX INT48_MAX
  478. # define __UINT_LEAST8_MAX UINT48_MAX
  479. #endif /* __INT48_TYPE__ */
  480. #ifdef __INT40_TYPE__
  481. # define INT40_MAX INT40_C(549755813887)
  482. # define INT40_MIN (-INT40_C(549755813887)-1)
  483. # define UINT40_MAX UINT40_C(1099511627775)
  484. # define INT_LEAST40_MIN INT40_MIN
  485. # define INT_LEAST40_MAX INT40_MAX
  486. # define UINT_LEAST40_MAX UINT40_MAX
  487. # define INT_FAST40_MIN INT40_MIN
  488. # define INT_FAST40_MAX INT40_MAX
  489. # define UINT_FAST40_MAX UINT40_MAX
  490. # define __INT_LEAST32_MIN INT40_MIN
  491. # define __INT_LEAST32_MAX INT40_MAX
  492. # define __UINT_LEAST32_MAX UINT40_MAX
  493. # define __INT_LEAST16_MIN INT40_MIN
  494. # define __INT_LEAST16_MAX INT40_MAX
  495. # define __UINT_LEAST16_MAX UINT40_MAX
  496. # define __INT_LEAST8_MIN INT40_MIN
  497. # define __INT_LEAST8_MAX INT40_MAX
  498. # define __UINT_LEAST8_MAX UINT40_MAX
  499. #endif /* __INT40_TYPE__ */
  500. #ifdef __INT32_TYPE__
  501. # define INT32_MAX INT32_C(2147483647)
  502. # define INT32_MIN (-INT32_C(2147483647)-1)
  503. # define UINT32_MAX UINT32_C(4294967295)
  504. # define __INT_LEAST32_MIN INT32_MIN
  505. # define __INT_LEAST32_MAX INT32_MAX
  506. # define __UINT_LEAST32_MAX UINT32_MAX
  507. # define __INT_LEAST16_MIN INT32_MIN
  508. # define __INT_LEAST16_MAX INT32_MAX
  509. # define __UINT_LEAST16_MAX UINT32_MAX
  510. # define __INT_LEAST8_MIN INT32_MIN
  511. # define __INT_LEAST8_MAX INT32_MAX
  512. # define __UINT_LEAST8_MAX UINT32_MAX
  513. #endif /* __INT32_TYPE__ */
  514. #ifdef __INT_LEAST32_MIN
  515. # define INT_LEAST32_MIN __INT_LEAST32_MIN
  516. # define INT_LEAST32_MAX __INT_LEAST32_MAX
  517. # define UINT_LEAST32_MAX __UINT_LEAST32_MAX
  518. # define INT_FAST32_MIN __INT_LEAST32_MIN
  519. # define INT_FAST32_MAX __INT_LEAST32_MAX
  520. # define UINT_FAST32_MAX __UINT_LEAST32_MAX
  521. #endif /* __INT_LEAST32_MIN */
  522. #ifdef __INT24_TYPE__
  523. # define INT24_MAX INT24_C(8388607)
  524. # define INT24_MIN (-INT24_C(8388607)-1)
  525. # define UINT24_MAX UINT24_C(16777215)
  526. # define INT_LEAST24_MIN INT24_MIN
  527. # define INT_LEAST24_MAX INT24_MAX
  528. # define UINT_LEAST24_MAX UINT24_MAX
  529. # define INT_FAST24_MIN INT24_MIN
  530. # define INT_FAST24_MAX INT24_MAX
  531. # define UINT_FAST24_MAX UINT24_MAX
  532. # define __INT_LEAST16_MIN INT24_MIN
  533. # define __INT_LEAST16_MAX INT24_MAX
  534. # define __UINT_LEAST16_MAX UINT24_MAX
  535. # define __INT_LEAST8_MIN INT24_MIN
  536. # define __INT_LEAST8_MAX INT24_MAX
  537. # define __UINT_LEAST8_MAX UINT24_MAX
  538. #endif /* __INT24_TYPE__ */
  539. #ifdef __INT16_TYPE__
  540. #define INT16_MAX INT16_C(32767)
  541. #define INT16_MIN (-INT16_C(32767)-1)
  542. #define UINT16_MAX UINT16_C(65535)
  543. # define __INT_LEAST16_MIN INT16_MIN
  544. # define __INT_LEAST16_MAX INT16_MAX
  545. # define __UINT_LEAST16_MAX UINT16_MAX
  546. # define __INT_LEAST8_MIN INT16_MIN
  547. # define __INT_LEAST8_MAX INT16_MAX
  548. # define __UINT_LEAST8_MAX UINT16_MAX
  549. #endif /* __INT16_TYPE__ */
  550. #ifdef __INT_LEAST16_MIN
  551. # define INT_LEAST16_MIN __INT_LEAST16_MIN
  552. # define INT_LEAST16_MAX __INT_LEAST16_MAX
  553. # define UINT_LEAST16_MAX __UINT_LEAST16_MAX
  554. # define INT_FAST16_MIN __INT_LEAST16_MIN
  555. # define INT_FAST16_MAX __INT_LEAST16_MAX
  556. # define UINT_FAST16_MAX __UINT_LEAST16_MAX
  557. #endif /* __INT_LEAST16_MIN */
  558. #ifdef __INT8_TYPE__
  559. # define INT8_MAX INT8_C(127)
  560. # define INT8_MIN (-INT8_C(127)-1)
  561. # define UINT8_MAX UINT8_C(255)
  562. # define __INT_LEAST8_MIN INT8_MIN
  563. # define __INT_LEAST8_MAX INT8_MAX
  564. # define __UINT_LEAST8_MAX UINT8_MAX
  565. #endif /* __INT8_TYPE__ */
  566. #ifdef __INT_LEAST8_MIN
  567. # define INT_LEAST8_MIN __INT_LEAST8_MIN
  568. # define INT_LEAST8_MAX __INT_LEAST8_MAX
  569. # define UINT_LEAST8_MAX __UINT_LEAST8_MAX
  570. # define INT_FAST8_MIN __INT_LEAST8_MIN
  571. # define INT_FAST8_MAX __INT_LEAST8_MAX
  572. # define UINT_FAST8_MAX __UINT_LEAST8_MAX
  573. #endif /* __INT_LEAST8_MIN */
  574. /* Some utility macros */
  575. #define __INTN_MIN(n) __stdint_join3( INT, n, _MIN)
  576. #define __INTN_MAX(n) __stdint_join3( INT, n, _MAX)
  577. #define __UINTN_MAX(n) __stdint_join3(UINT, n, _MAX)
  578. #define __INTN_C(n, v) __stdint_join3( INT, n, _C(v))
  579. #define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v))
  580. /* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */
  581. /* C99 7.18.3 Limits of other integer types. */
  582. #define INTPTR_MIN (-__INTPTR_MAX__-1)
  583. #define INTPTR_MAX __INTPTR_MAX__
  584. #define UINTPTR_MAX __UINTPTR_MAX__
  585. #define PTRDIFF_MIN (-__PTRDIFF_MAX__-1)
  586. #define PTRDIFF_MAX __PTRDIFF_MAX__
  587. #define SIZE_MAX __SIZE_MAX__
  588. /* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__
  589. * is enabled. */
  590. #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
  591. #define RSIZE_MAX (SIZE_MAX >> 1)
  592. #endif
  593. /* C99 7.18.2.5 Limits of greatest-width integer types. */
  594. #define INTMAX_MIN (-__INTMAX_MAX__-1)
  595. #define INTMAX_MAX __INTMAX_MAX__
  596. #define UINTMAX_MAX __UINTMAX_MAX__
  597. /* C99 7.18.3 Limits of other integer types. */
  598. #define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__)
  599. #define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__)
  600. #ifdef __WINT_UNSIGNED__
  601. # define WINT_MIN __UINTN_C(__WINT_WIDTH__, 0)
  602. # define WINT_MAX __UINTN_MAX(__WINT_WIDTH__)
  603. #else
  604. # define WINT_MIN __INTN_MIN(__WINT_WIDTH__)
  605. # define WINT_MAX __INTN_MAX(__WINT_WIDTH__)
  606. #endif
  607. #ifndef WCHAR_MAX
  608. # define WCHAR_MAX __WCHAR_MAX__
  609. #endif
  610. #ifndef WCHAR_MIN
  611. # if __WCHAR_MAX__ == __INTN_MAX(__WCHAR_WIDTH__)
  612. # define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__)
  613. # else
  614. # define WCHAR_MIN __UINTN_C(__WCHAR_WIDTH__, 0)
  615. # endif
  616. #endif
  617. /* 7.18.4.2 Macros for greatest-width integer constants. */
  618. #define INTMAX_C(v) __int_c(v, __INTMAX_C_SUFFIX__)
  619. #define UINTMAX_C(v) __int_c(v, __UINTMAX_C_SUFFIX__)
  620. #endif /* __CLANG_STDINT_H */
  621. #endif /* __STDC_HOSTED__ */