stdint.h 8.7 KB

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