stdint.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* Copyright (C) 1997-2016 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. #include <features.h>
  20. #include <bits/wchar.h>
  21. #include <bits/wordsize.h>
  22. /* Exact integral types. */
  23. /* Signed. */
  24. /* There is some amount of overlap with <sys/types.h> as known by inet code */
  25. #ifndef __int8_t_defined
  26. # define __int8_t_defined
  27. typedef signed char int8_t;
  28. typedef short int int16_t;
  29. typedef int int32_t;
  30. # if __WORDSIZE == 64
  31. typedef long int int64_t;
  32. # else
  33. __extension__
  34. typedef long long int int64_t;
  35. # endif
  36. #endif
  37. /* Unsigned. */
  38. typedef unsigned char uint8_t;
  39. typedef unsigned short int uint16_t;
  40. #ifndef __uint32_t_defined
  41. typedef unsigned int uint32_t;
  42. # define __uint32_t_defined
  43. #endif
  44. #if __WORDSIZE == 64
  45. typedef unsigned long int uint64_t;
  46. #else
  47. __extension__
  48. typedef unsigned long long int uint64_t;
  49. #endif
  50. /* Small types. */
  51. /* Signed. */
  52. typedef signed char int_least8_t;
  53. typedef short int int_least16_t;
  54. typedef int int_least32_t;
  55. #if __WORDSIZE == 64
  56. typedef long int int_least64_t;
  57. #else
  58. __extension__
  59. typedef long long int int_least64_t;
  60. #endif
  61. /* Unsigned. */
  62. typedef unsigned char uint_least8_t;
  63. typedef unsigned short int uint_least16_t;
  64. typedef unsigned int uint_least32_t;
  65. #if __WORDSIZE == 64
  66. typedef unsigned long int uint_least64_t;
  67. #else
  68. __extension__
  69. typedef unsigned long long int uint_least64_t;
  70. #endif
  71. /* Fast types. */
  72. /* Signed. */
  73. typedef signed char int_fast8_t;
  74. #if __WORDSIZE == 64
  75. typedef long int int_fast16_t;
  76. typedef long int int_fast32_t;
  77. typedef long int int_fast64_t;
  78. #else
  79. typedef int int_fast16_t;
  80. typedef int int_fast32_t;
  81. __extension__
  82. typedef long long int int_fast64_t;
  83. #endif
  84. /* Unsigned. */
  85. typedef unsigned char uint_fast8_t;
  86. #if __WORDSIZE == 64
  87. typedef unsigned long int uint_fast16_t;
  88. typedef unsigned long int uint_fast32_t;
  89. typedef unsigned long int uint_fast64_t;
  90. #else
  91. typedef unsigned int uint_fast16_t;
  92. typedef unsigned int uint_fast32_t;
  93. __extension__
  94. typedef unsigned long long int uint_fast64_t;
  95. #endif
  96. /* Types for `void *' pointers. */
  97. #if __WORDSIZE == 64
  98. # ifndef __intptr_t_defined
  99. typedef long int intptr_t;
  100. # define __intptr_t_defined
  101. # endif
  102. typedef unsigned long int uintptr_t;
  103. #else
  104. # ifndef __intptr_t_defined
  105. typedef int intptr_t;
  106. # define __intptr_t_defined
  107. # endif
  108. typedef unsigned int uintptr_t;
  109. #endif
  110. /* Largest integral types. */
  111. #if __WORDSIZE == 64
  112. typedef long int intmax_t;
  113. typedef unsigned long int uintmax_t;
  114. #else
  115. __extension__
  116. typedef long long int intmax_t;
  117. __extension__
  118. typedef unsigned long long int uintmax_t;
  119. #endif
  120. # if __WORDSIZE == 64
  121. # define __INT64_C(c) c ## L
  122. # define __UINT64_C(c) c ## UL
  123. # else
  124. # define __INT64_C(c) c ## LL
  125. # define __UINT64_C(c) c ## ULL
  126. # endif
  127. /* Limits of integral types. */
  128. /* Minimum of signed integral types. */
  129. # define INT8_MIN (-128)
  130. # define INT16_MIN (-32767-1)
  131. # define INT32_MIN (-2147483647-1)
  132. # define INT64_MIN (-__INT64_C(9223372036854775807)-1)
  133. /* Maximum of signed integral types. */
  134. # define INT8_MAX (127)
  135. # define INT16_MAX (32767)
  136. # define INT32_MAX (2147483647)
  137. # define INT64_MAX (__INT64_C(9223372036854775807))
  138. /* Maximum of unsigned integral types. */
  139. # define UINT8_MAX (255)
  140. # define UINT16_MAX (65535)
  141. # define UINT32_MAX (4294967295U)
  142. # define UINT64_MAX (__UINT64_C(18446744073709551615))
  143. /* Minimum of signed integral types having a minimum size. */
  144. # define INT_LEAST8_MIN (-128)
  145. # define INT_LEAST16_MIN (-32767-1)
  146. # define INT_LEAST32_MIN (-2147483647-1)
  147. # define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1)
  148. /* Maximum of signed integral types having a minimum size. */
  149. # define INT_LEAST8_MAX (127)
  150. # define INT_LEAST16_MAX (32767)
  151. # define INT_LEAST32_MAX (2147483647)
  152. # define INT_LEAST64_MAX (__INT64_C(9223372036854775807))
  153. /* Maximum of unsigned integral types having a minimum size. */
  154. # define UINT_LEAST8_MAX (255)
  155. # define UINT_LEAST16_MAX (65535)
  156. # define UINT_LEAST32_MAX (4294967295U)
  157. # define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615))
  158. /* Minimum of fast signed integral types having a minimum size. */
  159. # define INT_FAST8_MIN (-128)
  160. # if __WORDSIZE == 64
  161. # define INT_FAST16_MIN (-9223372036854775807L-1)
  162. # define INT_FAST32_MIN (-9223372036854775807L-1)
  163. # else
  164. # define INT_FAST16_MIN (-2147483647-1)
  165. # define INT_FAST32_MIN (-2147483647-1)
  166. # endif
  167. # define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1)
  168. /* Maximum of fast signed integral types having a minimum size. */
  169. # define INT_FAST8_MAX (127)
  170. # if __WORDSIZE == 64
  171. # define INT_FAST16_MAX (9223372036854775807L)
  172. # define INT_FAST32_MAX (9223372036854775807L)
  173. # else
  174. # define INT_FAST16_MAX (2147483647)
  175. # define INT_FAST32_MAX (2147483647)
  176. # endif
  177. # define INT_FAST64_MAX (__INT64_C(9223372036854775807))
  178. /* Maximum of fast unsigned integral types having a minimum size. */
  179. # define UINT_FAST8_MAX (255)
  180. # if __WORDSIZE == 64
  181. # define UINT_FAST16_MAX (18446744073709551615UL)
  182. # define UINT_FAST32_MAX (18446744073709551615UL)
  183. # else
  184. # define UINT_FAST16_MAX (4294967295U)
  185. # define UINT_FAST32_MAX (4294967295U)
  186. # endif
  187. # define UINT_FAST64_MAX (__UINT64_C(18446744073709551615))
  188. /* Values to test for integral types holding `void *' pointer. */
  189. # if __WORDSIZE == 64
  190. # define INTPTR_MIN (-9223372036854775807L-1)
  191. # define INTPTR_MAX (9223372036854775807L)
  192. # define UINTPTR_MAX (18446744073709551615UL)
  193. # else
  194. # define INTPTR_MIN (-2147483647-1)
  195. # define INTPTR_MAX (2147483647)
  196. # define UINTPTR_MAX (4294967295U)
  197. # endif
  198. /* Minimum for largest signed integral type. */
  199. # define INTMAX_MIN (-__INT64_C(9223372036854775807)-1)
  200. /* Maximum for largest signed integral type. */
  201. # define INTMAX_MAX (__INT64_C(9223372036854775807))
  202. /* Maximum for largest unsigned integral type. */
  203. # define UINTMAX_MAX (__UINT64_C(18446744073709551615))
  204. /* Limits of other integer types. */
  205. /* Limits of `ptrdiff_t' type. */
  206. # if __WORDSIZE == 64
  207. # define PTRDIFF_MIN (-9223372036854775807L-1)
  208. # define PTRDIFF_MAX (9223372036854775807L)
  209. # else
  210. # define PTRDIFF_MIN (-2147483647-1)
  211. # define PTRDIFF_MAX (2147483647)
  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. # ifdef __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. #endif /* stdint.h */