stdint.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. /* The ISO C99 standard specifies that in C++ implementations these
  123. macros should only be defined if explicitly requested. */
  124. #if !defined __cplusplus || defined __STDC_LIMIT_MACROS
  125. # if __WORDSIZE == 64
  126. # define __INT64_C(c) c ## L
  127. # define __UINT64_C(c) c ## UL
  128. # else
  129. # define __INT64_C(c) c ## LL
  130. # define __UINT64_C(c) c ## ULL
  131. # endif
  132. /* Limits of integral types. */
  133. /* Minimum of signed integral types. */
  134. # define INT8_MIN (-128)
  135. # define INT16_MIN (-32767-1)
  136. # define INT32_MIN (-2147483647-1)
  137. # define INT64_MIN (-__INT64_C(9223372036854775807)-1)
  138. /* Maximum of signed integral types. */
  139. # define INT8_MAX (127)
  140. # define INT16_MAX (32767)
  141. # define INT32_MAX (2147483647)
  142. # define INT64_MAX (__INT64_C(9223372036854775807))
  143. /* Maximum of unsigned integral types. */
  144. # define UINT8_MAX (255)
  145. # define UINT16_MAX (65535)
  146. # define UINT32_MAX (4294967295U)
  147. # define UINT64_MAX (__UINT64_C(18446744073709551615))
  148. /* Minimum of signed integral types having a minimum size. */
  149. # define INT_LEAST8_MIN (-128)
  150. # define INT_LEAST16_MIN (-32767-1)
  151. # define INT_LEAST32_MIN (-2147483647-1)
  152. # define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1)
  153. /* Maximum of signed integral types having a minimum size. */
  154. # define INT_LEAST8_MAX (127)
  155. # define INT_LEAST16_MAX (32767)
  156. # define INT_LEAST32_MAX (2147483647)
  157. # define INT_LEAST64_MAX (__INT64_C(9223372036854775807))
  158. /* Maximum of unsigned integral types having a minimum size. */
  159. # define UINT_LEAST8_MAX (255)
  160. # define UINT_LEAST16_MAX (65535)
  161. # define UINT_LEAST32_MAX (4294967295U)
  162. # define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615))
  163. /* Minimum of fast signed integral types having a minimum size. */
  164. # define INT_FAST8_MIN (-128)
  165. # if __WORDSIZE == 64
  166. # define INT_FAST16_MIN (-9223372036854775807L-1)
  167. # define INT_FAST32_MIN (-9223372036854775807L-1)
  168. # else
  169. # define INT_FAST16_MIN (-2147483647-1)
  170. # define INT_FAST32_MIN (-2147483647-1)
  171. # endif
  172. # define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1)
  173. /* Maximum of fast signed integral types having a minimum size. */
  174. # define INT_FAST8_MAX (127)
  175. # if __WORDSIZE == 64
  176. # define INT_FAST16_MAX (9223372036854775807L)
  177. # define INT_FAST32_MAX (9223372036854775807L)
  178. # else
  179. # define INT_FAST16_MAX (2147483647)
  180. # define INT_FAST32_MAX (2147483647)
  181. # endif
  182. # define INT_FAST64_MAX (__INT64_C(9223372036854775807))
  183. /* Maximum of fast unsigned integral types having a minimum size. */
  184. # define UINT_FAST8_MAX (255)
  185. # if __WORDSIZE == 64
  186. # define UINT_FAST16_MAX (18446744073709551615UL)
  187. # define UINT_FAST32_MAX (18446744073709551615UL)
  188. # else
  189. # define UINT_FAST16_MAX (4294967295U)
  190. # define UINT_FAST32_MAX (4294967295U)
  191. # endif
  192. # define UINT_FAST64_MAX (__UINT64_C(18446744073709551615))
  193. /* Values to test for integral types holding `void *' pointer. */
  194. # if __WORDSIZE == 64
  195. # define INTPTR_MIN (-9223372036854775807L-1)
  196. # define INTPTR_MAX (9223372036854775807L)
  197. # define UINTPTR_MAX (18446744073709551615UL)
  198. # else
  199. # define INTPTR_MIN (-2147483647-1)
  200. # define INTPTR_MAX (2147483647)
  201. # define UINTPTR_MAX (4294967295U)
  202. # endif
  203. /* Minimum for largest signed integral type. */
  204. # define INTMAX_MIN (-__INT64_C(9223372036854775807)-1)
  205. /* Maximum for largest signed integral type. */
  206. # define INTMAX_MAX (__INT64_C(9223372036854775807))
  207. /* Maximum for largest unsigned integral type. */
  208. # define UINTMAX_MAX (__UINT64_C(18446744073709551615))
  209. /* Limits of other integer types. */
  210. /* Limits of `ptrdiff_t' type. */
  211. # if __WORDSIZE == 64
  212. # define PTRDIFF_MIN (-9223372036854775807L-1)
  213. # define PTRDIFF_MAX (9223372036854775807L)
  214. # else
  215. # define PTRDIFF_MIN (-2147483647-1)
  216. # define PTRDIFF_MAX (2147483647)
  217. # endif
  218. /* Limits of `sig_atomic_t'. */
  219. # define SIG_ATOMIC_MIN (-2147483647-1)
  220. # define SIG_ATOMIC_MAX (2147483647)
  221. /* Limit of `size_t' type. */
  222. # if __WORDSIZE == 64
  223. # define SIZE_MAX (18446744073709551615UL)
  224. # else
  225. # define SIZE_MAX (4294967295U)
  226. # endif
  227. #ifdef __UCLIBC_HAS_WCHAR__
  228. /* Limits of `wchar_t'. */
  229. # ifndef WCHAR_MIN
  230. /* These constants might also be defined in <wchar.h>. */
  231. # define WCHAR_MIN __WCHAR_MIN
  232. # define WCHAR_MAX __WCHAR_MAX
  233. # endif
  234. /* Limits of `wint_t'. */
  235. # define WINT_MIN (0u)
  236. # define WINT_MAX (4294967295u)
  237. #endif /* __UCLIBC_HAS_WCHAR__ */
  238. #endif /* C++ && limit macros */
  239. /* The ISO C99 standard specifies that in C++ implementations these
  240. should only be defined if explicitly requested. */
  241. #if !defined __cplusplus || defined __STDC_CONSTANT_MACROS
  242. /* Signed. */
  243. # define INT8_C(c) c
  244. # define INT16_C(c) c
  245. # define INT32_C(c) c
  246. # if __WORDSIZE == 64
  247. # define INT64_C(c) c ## L
  248. # else
  249. # define INT64_C(c) c ## LL
  250. # endif
  251. /* Unsigned. */
  252. # define UINT8_C(c) c
  253. # define UINT16_C(c) c
  254. # define UINT32_C(c) c ## U
  255. # if __WORDSIZE == 64
  256. # define UINT64_C(c) c ## UL
  257. # else
  258. # define UINT64_C(c) c ## ULL
  259. # endif
  260. /* Maximal type. */
  261. # if __WORDSIZE == 64
  262. # define INTMAX_C(c) c ## L
  263. # define UINTMAX_C(c) c ## UL
  264. # else
  265. # define INTMAX_C(c) c ## LL
  266. # define UINTMAX_C(c) c ## ULL
  267. # endif
  268. #endif /* C++ && constant macros */
  269. #endif /* stdint.h */