stdint.h 6.5 KB

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