stdint.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* Copyright (C) 1997,1998,1999,2000,2001,2006 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. #ifdef __UCLIBC_HAS_WCHAR__
  21. #include <bits/wchar.h>
  22. #endif /* __UCLIBC_HAS_WCHAR__ */
  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. #if __WORDSIZE == 64
  114. typedef long int intmax_t;
  115. typedef unsigned long int uintmax_t;
  116. #else
  117. __extension__
  118. typedef long long int intmax_t;
  119. __extension__
  120. typedef unsigned long long int uintmax_t;
  121. #endif
  122. # if __WORDSIZE == 64
  123. # define __INT64_C(c) c ## L
  124. # define __UINT64_C(c) c ## UL
  125. # else
  126. # define __INT64_C(c) c ## LL
  127. # define __UINT64_C(c) c ## ULL
  128. # endif
  129. /* Limits of integral types. */
  130. /* Minimum of signed integral types. */
  131. # define INT8_MIN (-128)
  132. # define INT16_MIN (-32767-1)
  133. # define INT32_MIN (-2147483647-1)
  134. # define INT64_MIN (-__INT64_C(9223372036854775807)-1)
  135. /* Maximum of signed integral types. */
  136. # define INT8_MAX (127)
  137. # define INT16_MAX (32767)
  138. # define INT32_MAX (2147483647)
  139. # define INT64_MAX (__INT64_C(9223372036854775807))
  140. /* Maximum of unsigned integral types. */
  141. # define UINT8_MAX (255)
  142. # define UINT16_MAX (65535)
  143. # define UINT32_MAX (4294967295U)
  144. # define UINT64_MAX (__UINT64_C(18446744073709551615))
  145. /* Minimum of signed integral types having a minimum size. */
  146. # define INT_LEAST8_MIN (-128)
  147. # define INT_LEAST16_MIN (-32767-1)
  148. # define INT_LEAST32_MIN (-2147483647-1)
  149. # define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1)
  150. /* Maximum of signed integral types having a minimum size. */
  151. # define INT_LEAST8_MAX (127)
  152. # define INT_LEAST16_MAX (32767)
  153. # define INT_LEAST32_MAX (2147483647)
  154. # define INT_LEAST64_MAX (__INT64_C(9223372036854775807))
  155. /* Maximum of unsigned integral types having a minimum size. */
  156. # define UINT_LEAST8_MAX (255)
  157. # define UINT_LEAST16_MAX (65535)
  158. # define UINT_LEAST32_MAX (4294967295U)
  159. # define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615))
  160. /* Minimum of fast signed integral types having a minimum size. */
  161. # define INT_FAST8_MIN (-128)
  162. # if __WORDSIZE == 64
  163. # define INT_FAST16_MIN (-9223372036854775807L-1)
  164. # define INT_FAST32_MIN (-9223372036854775807L-1)
  165. # else
  166. # define INT_FAST16_MIN (-2147483647-1)
  167. # define INT_FAST32_MIN (-2147483647-1)
  168. # endif
  169. # define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1)
  170. /* Maximum of fast signed integral types having a minimum size. */
  171. # define INT_FAST8_MAX (127)
  172. # if __WORDSIZE == 64
  173. # define INT_FAST16_MAX (9223372036854775807L)
  174. # define INT_FAST32_MAX (9223372036854775807L)
  175. # else
  176. # define INT_FAST16_MAX (2147483647)
  177. # define INT_FAST32_MAX (2147483647)
  178. # endif
  179. # define INT_FAST64_MAX (__INT64_C(9223372036854775807))
  180. /* Maximum of fast unsigned integral types having a minimum size. */
  181. # define UINT_FAST8_MAX (255)
  182. # if __WORDSIZE == 64
  183. # define UINT_FAST16_MAX (18446744073709551615UL)
  184. # define UINT_FAST32_MAX (18446744073709551615UL)
  185. # else
  186. # define UINT_FAST16_MAX (4294967295U)
  187. # define UINT_FAST32_MAX (4294967295U)
  188. # endif
  189. # define UINT_FAST64_MAX (__UINT64_C(18446744073709551615))
  190. /* Values to test for integral types holding `void *' pointer. */
  191. # if __WORDSIZE == 64
  192. # define INTPTR_MIN (-9223372036854775807L-1)
  193. # define INTPTR_MAX (9223372036854775807L)
  194. # define UINTPTR_MAX (18446744073709551615UL)
  195. # else
  196. # define INTPTR_MIN (-2147483647-1)
  197. # define INTPTR_MAX (2147483647)
  198. # define UINTPTR_MAX (4294967295U)
  199. # endif
  200. /* Minimum for largest signed integral type. */
  201. # define INTMAX_MIN (-__INT64_C(9223372036854775807)-1)
  202. /* Maximum for largest signed integral type. */
  203. # define INTMAX_MAX (__INT64_C(9223372036854775807))
  204. /* Maximum for largest unsigned integral type. */
  205. # define UINTMAX_MAX (__UINT64_C(18446744073709551615))
  206. /* Limits of other integer types. */
  207. /* Limits of `ptrdiff_t' type. */
  208. # if __WORDSIZE == 64
  209. # define PTRDIFF_MIN (-9223372036854775807L-1)
  210. # define PTRDIFF_MAX (9223372036854775807L)
  211. # else
  212. # define PTRDIFF_MIN (-2147483647-1)
  213. # define PTRDIFF_MAX (2147483647)
  214. # endif
  215. /* Limits of `sig_atomic_t'. */
  216. # define SIG_ATOMIC_MIN (-2147483647-1)
  217. # define SIG_ATOMIC_MAX (2147483647)
  218. /* Limit of `size_t' type. */
  219. # if __WORDSIZE == 64
  220. # define SIZE_MAX (18446744073709551615UL)
  221. # else
  222. # define SIZE_MAX (4294967295U)
  223. # endif
  224. #ifdef __UCLIBC_HAS_WCHAR__
  225. /* Limits of `wchar_t'. */
  226. # ifndef WCHAR_MIN
  227. /* These constants might also be defined in <wchar.h>. */
  228. # define WCHAR_MIN __WCHAR_MIN
  229. # define WCHAR_MAX __WCHAR_MAX
  230. # endif
  231. /* Limits of `wint_t'. */
  232. # define WINT_MIN (0u)
  233. # define WINT_MAX (4294967295u)
  234. #endif /* __UCLIBC_HAS_WCHAR__ */
  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 */