stdint.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /* Copyright (C) 1997-2026 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. #if __GLIBC_USE (ISOC23)
  25. # define __STDC_VERSION_STDINT_H__ 202311L
  26. #endif
  27. /* Exact integral types. */
  28. /* Signed. */
  29. #include <bits/stdint-intn.h>
  30. /* Unsigned. */
  31. #include <bits/stdint-uintn.h>
  32. /* Small types. */
  33. #include <bits/stdint-least.h>
  34. /* Fast types. */
  35. /* Signed. */
  36. typedef signed char int_fast8_t;
  37. #if __WORDSIZE == 64
  38. typedef long int int_fast16_t;
  39. typedef long int int_fast32_t;
  40. typedef long int int_fast64_t;
  41. #else
  42. typedef int int_fast16_t;
  43. typedef int int_fast32_t;
  44. __extension__
  45. typedef long long int int_fast64_t;
  46. #endif
  47. /* Unsigned. */
  48. typedef unsigned char uint_fast8_t;
  49. #if __WORDSIZE == 64
  50. typedef unsigned long int uint_fast16_t;
  51. typedef unsigned long int uint_fast32_t;
  52. typedef unsigned long int uint_fast64_t;
  53. #else
  54. typedef unsigned int uint_fast16_t;
  55. typedef unsigned int uint_fast32_t;
  56. __extension__
  57. typedef unsigned long long int uint_fast64_t;
  58. #endif
  59. /* Types for `void *' pointers. */
  60. #if __WORDSIZE == 64
  61. # ifndef __intptr_t_defined
  62. typedef long int intptr_t;
  63. # define __intptr_t_defined
  64. # endif
  65. typedef unsigned long int uintptr_t;
  66. #else
  67. # ifndef __intptr_t_defined
  68. typedef int intptr_t;
  69. # define __intptr_t_defined
  70. # endif
  71. typedef unsigned int uintptr_t;
  72. #endif
  73. /* Largest integral types. */
  74. typedef __intmax_t intmax_t;
  75. typedef __uintmax_t uintmax_t;
  76. # undef __INT64_C
  77. # undef __UINT64_C
  78. # if __WORDSIZE == 64
  79. # define __INT64_C(c) c ## L
  80. # define __UINT64_C(c) c ## UL
  81. # else
  82. # define __INT64_C(c) c ## LL
  83. # define __UINT64_C(c) c ## ULL
  84. # endif
  85. /* Limits of integral types. */
  86. /* Minimum of signed integral types. */
  87. # define INT8_MIN (-128)
  88. # define INT16_MIN (-32767-1)
  89. # define INT32_MIN (-2147483647-1)
  90. # define INT64_MIN (-__INT64_C(9223372036854775807)-1)
  91. /* Maximum of signed integral types. */
  92. # define INT8_MAX (127)
  93. # define INT16_MAX (32767)
  94. # define INT32_MAX (2147483647)
  95. # define INT64_MAX (__INT64_C(9223372036854775807))
  96. /* Maximum of unsigned integral types. */
  97. # define UINT8_MAX (255)
  98. # define UINT16_MAX (65535)
  99. # define UINT32_MAX (4294967295U)
  100. # define UINT64_MAX (__UINT64_C(18446744073709551615))
  101. /* Minimum of signed integral types having a minimum size. */
  102. # define INT_LEAST8_MIN (-128)
  103. # define INT_LEAST16_MIN (-32767-1)
  104. # define INT_LEAST32_MIN (-2147483647-1)
  105. # define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1)
  106. /* Maximum of signed integral types having a minimum size. */
  107. # define INT_LEAST8_MAX (127)
  108. # define INT_LEAST16_MAX (32767)
  109. # define INT_LEAST32_MAX (2147483647)
  110. # define INT_LEAST64_MAX (__INT64_C(9223372036854775807))
  111. /* Maximum of unsigned integral types having a minimum size. */
  112. # define UINT_LEAST8_MAX (255)
  113. # define UINT_LEAST16_MAX (65535)
  114. # define UINT_LEAST32_MAX (4294967295U)
  115. # define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615))
  116. /* Minimum of fast signed integral types having a minimum size. */
  117. # define INT_FAST8_MIN (-128)
  118. # if __WORDSIZE == 64
  119. # define INT_FAST16_MIN (-9223372036854775807L-1)
  120. # define INT_FAST32_MIN (-9223372036854775807L-1)
  121. # else
  122. # define INT_FAST16_MIN (-2147483647-1)
  123. # define INT_FAST32_MIN (-2147483647-1)
  124. # endif
  125. # define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1)
  126. /* Maximum of fast signed integral types having a minimum size. */
  127. # define INT_FAST8_MAX (127)
  128. # if __WORDSIZE == 64
  129. # define INT_FAST16_MAX (9223372036854775807L)
  130. # define INT_FAST32_MAX (9223372036854775807L)
  131. # else
  132. # define INT_FAST16_MAX (2147483647)
  133. # define INT_FAST32_MAX (2147483647)
  134. # endif
  135. # define INT_FAST64_MAX (__INT64_C(9223372036854775807))
  136. /* Maximum of fast unsigned integral types having a minimum size. */
  137. # define UINT_FAST8_MAX (255)
  138. # if __WORDSIZE == 64
  139. # define UINT_FAST16_MAX (18446744073709551615UL)
  140. # define UINT_FAST32_MAX (18446744073709551615UL)
  141. # else
  142. # define UINT_FAST16_MAX (4294967295U)
  143. # define UINT_FAST32_MAX (4294967295U)
  144. # endif
  145. # define UINT_FAST64_MAX (__UINT64_C(18446744073709551615))
  146. /* Values to test for integral types holding `void *' pointer. */
  147. # if __WORDSIZE == 64
  148. # define INTPTR_MIN (-9223372036854775807L-1)
  149. # define INTPTR_MAX (9223372036854775807L)
  150. # define UINTPTR_MAX (18446744073709551615UL)
  151. # else
  152. # define INTPTR_MIN (-2147483647-1)
  153. # define INTPTR_MAX (2147483647)
  154. # define UINTPTR_MAX (4294967295U)
  155. # endif
  156. /* Minimum for largest signed integral type. */
  157. # define INTMAX_MIN (-__INT64_C(9223372036854775807)-1)
  158. /* Maximum for largest signed integral type. */
  159. # define INTMAX_MAX (__INT64_C(9223372036854775807))
  160. /* Maximum for largest unsigned integral type. */
  161. # define UINTMAX_MAX (__UINT64_C(18446744073709551615))
  162. /* Limits of other integer types. */
  163. /* Limits of `ptrdiff_t' type. */
  164. # if __WORDSIZE == 64
  165. # define PTRDIFF_MIN (-9223372036854775807L-1)
  166. # define PTRDIFF_MAX (9223372036854775807L)
  167. # else
  168. # if __WORDSIZE32_PTRDIFF_LONG
  169. # define PTRDIFF_MIN (-2147483647L-1)
  170. # define PTRDIFF_MAX (2147483647L)
  171. # else
  172. # define PTRDIFF_MIN (-2147483647-1)
  173. # define PTRDIFF_MAX (2147483647)
  174. # endif
  175. # endif
  176. /* Limits of `sig_atomic_t'. */
  177. # define SIG_ATOMIC_MIN (-2147483647-1)
  178. # define SIG_ATOMIC_MAX (2147483647)
  179. /* Limit of `size_t' type. */
  180. # if __WORDSIZE == 64
  181. # define SIZE_MAX (18446744073709551615UL)
  182. # else
  183. # if __WORDSIZE32_SIZE_ULONG
  184. # define SIZE_MAX (4294967295UL)
  185. # else
  186. # define SIZE_MAX (4294967295U)
  187. # endif
  188. # endif
  189. /* Limits of `wchar_t'. */
  190. # ifndef WCHAR_MIN
  191. /* These constants might also be defined in <wchar.h>. */
  192. # define WCHAR_MIN __WCHAR_MIN
  193. # define WCHAR_MAX __WCHAR_MAX
  194. # endif
  195. /* Limits of `wint_t'. */
  196. # define WINT_MIN (0u)
  197. # define WINT_MAX (4294967295u)
  198. /* Signed. */
  199. # define INT8_C(c) c
  200. # define INT16_C(c) c
  201. # define INT32_C(c) c
  202. # if __WORDSIZE == 64
  203. # define INT64_C(c) c ## L
  204. # else
  205. # define INT64_C(c) c ## LL
  206. # endif
  207. /* Unsigned. */
  208. # define UINT8_C(c) c
  209. # define UINT16_C(c) c
  210. # define UINT32_C(c) c ## U
  211. # if __WORDSIZE == 64
  212. # define UINT64_C(c) c ## UL
  213. # else
  214. # define UINT64_C(c) c ## ULL
  215. # endif
  216. /* Maximal type. */
  217. # if __WORDSIZE == 64
  218. # define INTMAX_C(c) c ## L
  219. # define UINTMAX_C(c) c ## UL
  220. # else
  221. # define INTMAX_C(c) c ## LL
  222. # define UINTMAX_C(c) c ## ULL
  223. # endif
  224. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  225. # define INT8_WIDTH 8
  226. # define UINT8_WIDTH 8
  227. # define INT16_WIDTH 16
  228. # define UINT16_WIDTH 16
  229. # define INT32_WIDTH 32
  230. # define UINT32_WIDTH 32
  231. # define INT64_WIDTH 64
  232. # define UINT64_WIDTH 64
  233. # define INT_LEAST8_WIDTH 8
  234. # define UINT_LEAST8_WIDTH 8
  235. # define INT_LEAST16_WIDTH 16
  236. # define UINT_LEAST16_WIDTH 16
  237. # define INT_LEAST32_WIDTH 32
  238. # define UINT_LEAST32_WIDTH 32
  239. # define INT_LEAST64_WIDTH 64
  240. # define UINT_LEAST64_WIDTH 64
  241. # define INT_FAST8_WIDTH 8
  242. # define UINT_FAST8_WIDTH 8
  243. # define INT_FAST16_WIDTH __WORDSIZE
  244. # define UINT_FAST16_WIDTH __WORDSIZE
  245. # define INT_FAST32_WIDTH __WORDSIZE
  246. # define UINT_FAST32_WIDTH __WORDSIZE
  247. # define INT_FAST64_WIDTH 64
  248. # define UINT_FAST64_WIDTH 64
  249. # define INTPTR_WIDTH __WORDSIZE
  250. # define UINTPTR_WIDTH __WORDSIZE
  251. # define INTMAX_WIDTH 64
  252. # define UINTMAX_WIDTH 64
  253. # define PTRDIFF_WIDTH __WORDSIZE
  254. # define SIG_ATOMIC_WIDTH 32
  255. # define SIZE_WIDTH __WORDSIZE
  256. # define WCHAR_WIDTH 32
  257. # define WINT_WIDTH 32
  258. #endif
  259. #endif /* stdint.h */