stdint.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /* Copyright (C) 1997-2020 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99: 7.18 Integer types <stdint.h>
  16. */
  17. #ifndef _STDINT_H
  18. #define _STDINT_H 1
  19. #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
  20. #include <bits/libc-header-start.h>
  21. #include <bits/types.h>
  22. #include <bits/wchar.h>
  23. #include <bits/wordsize.h>
  24. /* Exact integral types. */
  25. /* Signed. */
  26. #include <bits/stdint-intn.h>
  27. /* Unsigned. */
  28. #include <bits/stdint-uintn.h>
  29. /* Small types. */
  30. /* Signed. */
  31. typedef __int_least8_t int_least8_t;
  32. typedef __int_least16_t int_least16_t;
  33. typedef __int_least32_t int_least32_t;
  34. typedef __int_least64_t int_least64_t;
  35. /* Unsigned. */
  36. typedef __uint_least8_t uint_least8_t;
  37. typedef __uint_least16_t uint_least16_t;
  38. typedef __uint_least32_t uint_least32_t;
  39. typedef __uint_least64_t uint_least64_t;
  40. /* Fast types. */
  41. /* Signed. */
  42. typedef signed char int_fast8_t;
  43. #if __WORDSIZE == 64
  44. typedef long int int_fast16_t;
  45. typedef long int int_fast32_t;
  46. typedef long int int_fast64_t;
  47. #else
  48. typedef int int_fast16_t;
  49. typedef int int_fast32_t;
  50. __extension__
  51. typedef long long int int_fast64_t;
  52. #endif
  53. /* Unsigned. */
  54. typedef unsigned char uint_fast8_t;
  55. #if __WORDSIZE == 64
  56. typedef unsigned long int uint_fast16_t;
  57. typedef unsigned long int uint_fast32_t;
  58. typedef unsigned long int uint_fast64_t;
  59. #else
  60. typedef unsigned int uint_fast16_t;
  61. typedef unsigned int uint_fast32_t;
  62. __extension__
  63. typedef unsigned long long int uint_fast64_t;
  64. #endif
  65. /* Types for `void *' pointers. */
  66. #if __WORDSIZE == 64
  67. # ifndef __intptr_t_defined
  68. typedef long int intptr_t;
  69. # define __intptr_t_defined
  70. # endif
  71. typedef unsigned long int uintptr_t;
  72. #else
  73. # ifndef __intptr_t_defined
  74. typedef int intptr_t;
  75. # define __intptr_t_defined
  76. # endif
  77. typedef unsigned int uintptr_t;
  78. #endif
  79. /* Largest integral types. */
  80. typedef __intmax_t intmax_t;
  81. typedef __uintmax_t uintmax_t;
  82. # if __WORDSIZE == 64
  83. # define __INT64_C(c) c ## L
  84. # define __UINT64_C(c) c ## UL
  85. # else
  86. # define __INT64_C(c) c ## LL
  87. # define __UINT64_C(c) c ## ULL
  88. # endif
  89. /* Limits of integral types. */
  90. /* Minimum of signed integral types. */
  91. # define INT8_MIN (-128)
  92. # define INT16_MIN (-32767-1)
  93. # define INT32_MIN (-2147483647-1)
  94. # define INT64_MIN (-__INT64_C(9223372036854775807)-1)
  95. /* Maximum of signed integral types. */
  96. # define INT8_MAX (127)
  97. # define INT16_MAX (32767)
  98. # define INT32_MAX (2147483647)
  99. # define INT64_MAX (__INT64_C(9223372036854775807))
  100. /* Maximum of unsigned integral types. */
  101. # define UINT8_MAX (255)
  102. # define UINT16_MAX (65535)
  103. # define UINT32_MAX (4294967295U)
  104. # define UINT64_MAX (__UINT64_C(18446744073709551615))
  105. /* Minimum of signed integral types having a minimum size. */
  106. # define INT_LEAST8_MIN (-128)
  107. # define INT_LEAST16_MIN (-32767-1)
  108. # define INT_LEAST32_MIN (-2147483647-1)
  109. # define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1)
  110. /* Maximum of signed integral types having a minimum size. */
  111. # define INT_LEAST8_MAX (127)
  112. # define INT_LEAST16_MAX (32767)
  113. # define INT_LEAST32_MAX (2147483647)
  114. # define INT_LEAST64_MAX (__INT64_C(9223372036854775807))
  115. /* Maximum of unsigned integral types having a minimum size. */
  116. # define UINT_LEAST8_MAX (255)
  117. # define UINT_LEAST16_MAX (65535)
  118. # define UINT_LEAST32_MAX (4294967295U)
  119. # define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615))
  120. /* Minimum of fast signed integral types having a minimum size. */
  121. # define INT_FAST8_MIN (-128)
  122. # if __WORDSIZE == 64
  123. # define INT_FAST16_MIN (-9223372036854775807L-1)
  124. # define INT_FAST32_MIN (-9223372036854775807L-1)
  125. # else
  126. # define INT_FAST16_MIN (-2147483647-1)
  127. # define INT_FAST32_MIN (-2147483647-1)
  128. # endif
  129. # define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1)
  130. /* Maximum of fast signed integral types having a minimum size. */
  131. # define INT_FAST8_MAX (127)
  132. # if __WORDSIZE == 64
  133. # define INT_FAST16_MAX (9223372036854775807L)
  134. # define INT_FAST32_MAX (9223372036854775807L)
  135. # else
  136. # define INT_FAST16_MAX (2147483647)
  137. # define INT_FAST32_MAX (2147483647)
  138. # endif
  139. # define INT_FAST64_MAX (__INT64_C(9223372036854775807))
  140. /* Maximum of fast unsigned integral types having a minimum size. */
  141. # define UINT_FAST8_MAX (255)
  142. # if __WORDSIZE == 64
  143. # define UINT_FAST16_MAX (18446744073709551615UL)
  144. # define UINT_FAST32_MAX (18446744073709551615UL)
  145. # else
  146. # define UINT_FAST16_MAX (4294967295U)
  147. # define UINT_FAST32_MAX (4294967295U)
  148. # endif
  149. # define UINT_FAST64_MAX (__UINT64_C(18446744073709551615))
  150. /* Values to test for integral types holding `void *' pointer. */
  151. # if __WORDSIZE == 64
  152. # define INTPTR_MIN (-9223372036854775807L-1)
  153. # define INTPTR_MAX (9223372036854775807L)
  154. # define UINTPTR_MAX (18446744073709551615UL)
  155. # else
  156. # define INTPTR_MIN (-2147483647-1)
  157. # define INTPTR_MAX (2147483647)
  158. # define UINTPTR_MAX (4294967295U)
  159. # endif
  160. /* Minimum for largest signed integral type. */
  161. # define INTMAX_MIN (-__INT64_C(9223372036854775807)-1)
  162. /* Maximum for largest signed integral type. */
  163. # define INTMAX_MAX (__INT64_C(9223372036854775807))
  164. /* Maximum for largest unsigned integral type. */
  165. # define UINTMAX_MAX (__UINT64_C(18446744073709551615))
  166. /* Limits of other integer types. */
  167. /* Limits of `ptrdiff_t' type. */
  168. # if __WORDSIZE == 64
  169. # define PTRDIFF_MIN (-9223372036854775807L-1)
  170. # define PTRDIFF_MAX (9223372036854775807L)
  171. # else
  172. # if __WORDSIZE32_PTRDIFF_LONG
  173. # define PTRDIFF_MIN (-2147483647L-1)
  174. # define PTRDIFF_MAX (2147483647L)
  175. # else
  176. # define PTRDIFF_MIN (-2147483647-1)
  177. # define PTRDIFF_MAX (2147483647)
  178. # endif
  179. # endif
  180. /* Limits of `sig_atomic_t'. */
  181. # define SIG_ATOMIC_MIN (-2147483647-1)
  182. # define SIG_ATOMIC_MAX (2147483647)
  183. /* Limit of `size_t' type. */
  184. # if __WORDSIZE == 64
  185. # define SIZE_MAX (18446744073709551615UL)
  186. # else
  187. # if __WORDSIZE32_SIZE_ULONG
  188. # define SIZE_MAX (4294967295UL)
  189. # else
  190. # define SIZE_MAX (4294967295U)
  191. # endif
  192. # endif
  193. /* Limits of `wchar_t'. */
  194. # ifndef WCHAR_MIN
  195. /* These constants might also be defined in <wchar.h>. */
  196. # define WCHAR_MIN __WCHAR_MIN
  197. # define WCHAR_MAX __WCHAR_MAX
  198. # endif
  199. /* Limits of `wint_t'. */
  200. # define WINT_MIN (0u)
  201. # define WINT_MAX (4294967295u)
  202. /* Signed. */
  203. # define INT8_C(c) c
  204. # define INT16_C(c) c
  205. # define INT32_C(c) c
  206. # if __WORDSIZE == 64
  207. # define INT64_C(c) c ## L
  208. # else
  209. # define INT64_C(c) c ## LL
  210. # endif
  211. /* Unsigned. */
  212. # define UINT8_C(c) c
  213. # define UINT16_C(c) c
  214. # define UINT32_C(c) c ## U
  215. # if __WORDSIZE == 64
  216. # define UINT64_C(c) c ## UL
  217. # else
  218. # define UINT64_C(c) c ## ULL
  219. # endif
  220. /* Maximal type. */
  221. # if __WORDSIZE == 64
  222. # define INTMAX_C(c) c ## L
  223. # define UINTMAX_C(c) c ## UL
  224. # else
  225. # define INTMAX_C(c) c ## LL
  226. # define UINTMAX_C(c) c ## ULL
  227. # endif
  228. #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
  229. # define INT8_WIDTH 8
  230. # define UINT8_WIDTH 8
  231. # define INT16_WIDTH 16
  232. # define UINT16_WIDTH 16
  233. # define INT32_WIDTH 32
  234. # define UINT32_WIDTH 32
  235. # define INT64_WIDTH 64
  236. # define UINT64_WIDTH 64
  237. # define INT_LEAST8_WIDTH 8
  238. # define UINT_LEAST8_WIDTH 8
  239. # define INT_LEAST16_WIDTH 16
  240. # define UINT_LEAST16_WIDTH 16
  241. # define INT_LEAST32_WIDTH 32
  242. # define UINT_LEAST32_WIDTH 32
  243. # define INT_LEAST64_WIDTH 64
  244. # define UINT_LEAST64_WIDTH 64
  245. # define INT_FAST8_WIDTH 8
  246. # define UINT_FAST8_WIDTH 8
  247. # define INT_FAST16_WIDTH __WORDSIZE
  248. # define UINT_FAST16_WIDTH __WORDSIZE
  249. # define INT_FAST32_WIDTH __WORDSIZE
  250. # define UINT_FAST32_WIDTH __WORDSIZE
  251. # define INT_FAST64_WIDTH 64
  252. # define UINT_FAST64_WIDTH 64
  253. # define INTPTR_WIDTH __WORDSIZE
  254. # define UINTPTR_WIDTH __WORDSIZE
  255. # define INTMAX_WIDTH 64
  256. # define UINTMAX_WIDTH 64
  257. # define PTRDIFF_WIDTH __WORDSIZE
  258. # define SIG_ATOMIC_WIDTH 32
  259. # define SIZE_WIDTH __WORDSIZE
  260. # define WCHAR_WIDTH 32
  261. # define WINT_WIDTH 32
  262. #endif
  263. #endif /* stdint.h */