stdint.h 9.0 KB

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