stdint.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * ISO C Standard: 7.18 Integer types <stdint.h>
  3. */
  4. #ifndef __STDINT_H__
  5. #define __STDINT_H__
  6. /* 7.8.1.1 Exact-width integer types */
  7. #ifdef __INT8_TYPE__
  8. typedef __INT8_TYPE__ int8_t;
  9. #endif
  10. #ifdef __INT16_TYPE__
  11. typedef __INT16_TYPE__ int16_t;
  12. #endif
  13. #ifdef __INT32_TYPE__
  14. typedef __INT32_TYPE__ int32_t;
  15. #endif
  16. #ifdef __INT64_TYPE__
  17. typedef __INT64_TYPE__ int64_t;
  18. #endif
  19. #ifdef __UINT8_TYPE__
  20. typedef __UINT8_TYPE__ uint8_t;
  21. #endif
  22. #ifdef __UINT16_TYPE__
  23. typedef __UINT16_TYPE__ uint16_t;
  24. #endif
  25. #ifdef __UINT32_TYPE__
  26. typedef __UINT32_TYPE__ uint32_t;
  27. #endif
  28. #ifdef __UINT64_TYPE__
  29. typedef __UINT64_TYPE__ uint64_t;
  30. #endif
  31. /* 7.8.1.2 Minimum-width integer types */
  32. typedef __INT_LEAST8_TYPE__ int_least8_t;
  33. typedef __INT_LEAST16_TYPE__ int_least16_t;
  34. typedef __INT_LEAST32_TYPE__ int_least32_t;
  35. typedef __INT_LEAST64_TYPE__ int_least64_t;
  36. typedef __UINT_LEAST8_TYPE__ uint_least8_t;
  37. typedef __UINT_LEAST16_TYPE__ uint_least16_t;
  38. typedef __UINT_LEAST32_TYPE__ uint_least32_t;
  39. typedef __UINT_LEAST64_TYPE__ uint_least64_t;
  40. /* 7.8.1.3 Fastest minimum-width integer types */
  41. typedef __INT_FAST8_TYPE__ int_fast8_t;
  42. typedef __INT_FAST16_TYPE__ int_fast16_t;
  43. typedef __INT_FAST32_TYPE__ int_fast32_t;
  44. typedef __INT_FAST64_TYPE__ int_fast64_t;
  45. typedef __UINT_FAST8_TYPE__ uint_fast8_t;
  46. typedef __UINT_FAST16_TYPE__ uint_fast16_t;
  47. typedef __UINT_FAST32_TYPE__ uint_fast32_t;
  48. typedef __UINT_FAST64_TYPE__ uint_fast64_t;
  49. /* 7.8.1.4 Integer types capable of holding object pointers */
  50. #ifdef __INTPTR_TYPE__
  51. typedef __INTPTR_TYPE__ intptr_t;
  52. #endif
  53. #ifdef __UINTPTR_TYPE__
  54. typedef __UINTPTR_TYPE__ uintptr_t;
  55. #endif
  56. /* 7.8.1.5 Greatest-width integer types */
  57. typedef __INTMAX_TYPE__ intmax_t;
  58. typedef __UINTMAX_TYPE__ uintmax_t;
  59. #if (!defined __cplusplus || __cplusplus >= 201103L \
  60. || defined __STDC_LIMIT_MACROS)
  61. /*
  62. * 7.18.2 Limits of specified-width integer types.
  63. *
  64. * The following object-like macros specify the minimum and maximum limits
  65. * of integer types corresponding to the typedef names defined above.
  66. */
  67. /* 7.18.2.1 Limits of exact-width integer types */
  68. #ifdef __INT8_MAX__
  69. # undef INT8_MAX
  70. # define INT8_MAX __INT8_MAX__
  71. # undef INT8_MIN
  72. # define INT8_MIN (-INT8_MAX - 1)
  73. #endif
  74. #ifdef __UINT8_MAX__
  75. # undef UINT8_MAX
  76. # define UINT8_MAX __UINT8_MAX__
  77. #endif
  78. #ifdef __INT16_MAX__
  79. # undef INT16_MAX
  80. # define INT16_MAX __INT16_MAX__
  81. # undef INT16_MIN
  82. # define INT16_MIN (-INT16_MAX - 1)
  83. #endif
  84. #ifdef __UINT16_MAX__
  85. # undef UINT16_MAX
  86. # define UINT16_MAX __UINT16_MAX__
  87. #endif
  88. #ifdef __INT32_MAX__
  89. # undef INT32_MAX
  90. # define INT32_MAX __INT32_MAX__
  91. # undef INT32_MIN
  92. # define INT32_MIN (-INT32_MAX - 1)
  93. #endif
  94. #ifdef __UINT32_MAX__
  95. # undef UINT32_MAX
  96. # define UINT32_MAX __UINT32_MAX__
  97. #endif
  98. #ifdef __INT64_MAX__
  99. # undef INT64_MAX
  100. # define INT64_MAX __INT64_MAX__
  101. # undef INT64_MIN
  102. # define INT64_MIN (-INT64_MAX - 1)
  103. #endif
  104. #ifdef __UINT64_MAX__
  105. # undef UINT64_MAX
  106. # define UINT64_MAX __UINT64_MAX__
  107. #endif
  108. #undef INT_LEAST8_MAX
  109. #define INT_LEAST8_MAX __INT_LEAST8_MAX__
  110. #undef INT_LEAST8_MIN
  111. #define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1)
  112. #undef UINT_LEAST8_MAX
  113. #define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
  114. #undef INT_LEAST16_MAX
  115. #define INT_LEAST16_MAX __INT_LEAST16_MAX__
  116. #undef INT_LEAST16_MIN
  117. #define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1)
  118. #undef UINT_LEAST16_MAX
  119. #define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
  120. #undef INT_LEAST32_MAX
  121. #define INT_LEAST32_MAX __INT_LEAST32_MAX__
  122. #undef INT_LEAST32_MIN
  123. #define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1)
  124. #undef UINT_LEAST32_MAX
  125. #define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
  126. #undef INT_LEAST64_MAX
  127. #define INT_LEAST64_MAX __INT_LEAST64_MAX__
  128. #undef INT_LEAST64_MIN
  129. #define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1)
  130. #undef UINT_LEAST64_MAX
  131. #define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
  132. #undef INT_FAST8_MAX
  133. #define INT_FAST8_MAX __INT_FAST8_MAX__
  134. #undef INT_FAST8_MIN
  135. #define INT_FAST8_MIN (-INT_FAST8_MAX - 1)
  136. #undef UINT_FAST8_MAX
  137. #define UINT_FAST8_MAX __UINT_FAST8_MAX__
  138. #undef INT_FAST16_MAX
  139. #define INT_FAST16_MAX __INT_FAST16_MAX__
  140. #undef INT_FAST16_MIN
  141. #define INT_FAST16_MIN (-INT_FAST16_MAX - 1)
  142. #undef UINT_FAST16_MAX
  143. #define UINT_FAST16_MAX __UINT_FAST16_MAX__
  144. #undef INT_FAST32_MAX
  145. #define INT_FAST32_MAX __INT_FAST32_MAX__
  146. #undef INT_FAST32_MIN
  147. #define INT_FAST32_MIN (-INT_FAST32_MAX - 1)
  148. #undef UINT_FAST32_MAX
  149. #define UINT_FAST32_MAX __UINT_FAST32_MAX__
  150. #undef INT_FAST64_MAX
  151. #define INT_FAST64_MAX __INT_FAST64_MAX__
  152. #undef INT_FAST64_MIN
  153. #define INT_FAST64_MIN (-INT_FAST64_MAX - 1)
  154. #undef UINT_FAST64_MAX
  155. #define UINT_FAST64_MAX __UINT_FAST64_MAX__
  156. #ifdef __INTPTR_MAX__
  157. # undef INTPTR_MAX
  158. # define INTPTR_MAX __INTPTR_MAX__
  159. # undef INTPTR_MIN
  160. # define INTPTR_MIN (-INTPTR_MAX - 1)
  161. #endif
  162. #ifdef __UINTPTR_MAX__
  163. # undef UINTPTR_MAX
  164. # define UINTPTR_MAX __UINTPTR_MAX__
  165. #endif
  166. #undef INTMAX_MAX
  167. #define INTMAX_MAX __INTMAX_MAX__
  168. #undef INTMAX_MIN
  169. #define INTMAX_MIN (-INTMAX_MAX - 1)
  170. #undef UINTMAX_MAX
  171. #define UINTMAX_MAX __UINTMAX_MAX__
  172. /* 7.18.3 Limits of other integer types */
  173. #undef PTRDIFF_MAX
  174. #define PTRDIFF_MAX __PTRDIFF_MAX__
  175. #undef PTRDIFF_MIN
  176. #define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
  177. #undef SIG_ATOMIC_MAX
  178. #define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
  179. #undef SIG_ATOMIC_MIN
  180. #define SIG_ATOMIC_MIN __SIG_ATOMIC_MIN__
  181. #undef SIZE_MAX
  182. #define SIZE_MAX __SIZE_MAX__
  183. #undef WCHAR_MAX
  184. #define WCHAR_MAX __WCHAR_MAX__
  185. #undef WCHAR_MIN
  186. #define WCHAR_MIN __WCHAR_MIN__
  187. #undef WINT_MAX
  188. #define WINT_MAX __WINT_MAX__
  189. #undef WINT_MIN
  190. #define WINT_MIN __WINT_MIN__
  191. #endif /* (!defined __cplusplus || __cplusplus >= 201103L
  192. || defined __STDC_LIMIT_MACROS) */
  193. #if (!defined __cplusplus || __cplusplus >= 201103L \
  194. || defined __STDC_CONSTANT_MACROS)
  195. #undef INT8_C
  196. #define INT8_C(c) __INT8_C(c)
  197. #undef INT16_C
  198. #define INT16_C(c) __INT16_C(c)
  199. #undef INT32_C
  200. #define INT32_C(c) __INT32_C(c)
  201. #undef INT64_C
  202. #define INT64_C(c) __INT64_C(c)
  203. #undef UINT8_C
  204. #define UINT8_C(c) __UINT8_C(c)
  205. #undef UINT16_C
  206. #define UINT16_C(c) __UINT16_C(c)
  207. #undef UINT32_C
  208. #define UINT32_C(c) __UINT32_C(c)
  209. #undef UINT64_C
  210. #define UINT64_C(c) __UINT64_C(c)
  211. #undef INTMAX_C
  212. #define INTMAX_C(c) __INTMAX_C(c)
  213. #undef UINTMAX_C
  214. #define UINTMAX_C(c) __UINTMAX_C(c)
  215. #endif /* (!defined __cplusplus || __cplusplus >= 201103L
  216. || defined __STDC_CONSTANT_MACROS) */
  217. #ifndef __INT_MAX__
  218. #define __INT_MAX__ 2147483647
  219. #endif
  220. #define INT_MIN (-1 - INT_MAX)
  221. #define INT_MAX (__INT_MAX__)
  222. #define UINT_MAX (INT_MAX * 2U + 1U)
  223. #define LONG_MAX ((long)(~0UL>>1))
  224. #define LONG_MIN (-LONG_MAX - 1)
  225. #define ULONG_MAX (~0UL)
  226. #endif