stdint.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /* Copyright (C) 1997, 1998, 1999, 2000 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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /*
  16. * ISO C99: 7.18 Integer types <stdint.h>
  17. */
  18. #ifndef _STDINT_H
  19. #define _STDINT_H 1
  20. #include <features.h>
  21. #ifdef __UCLIBC_HAS_WCHAR__
  22. #include <bits/wchar.h>
  23. #endif /* __UCLIBC_HAS_WCHAR__ */
  24. #include <bits/wordsize.h>
  25. /* Exact integral types. */
  26. /* Signed. */
  27. /* There is some amount of overlap with <sys/types.h> as known by inet code */
  28. #ifndef __int8_t_defined
  29. # define __int8_t_defined
  30. typedef signed char int8_t;
  31. typedef short int int16_t;
  32. typedef int int32_t;
  33. # if __WORDSIZE == 64
  34. typedef long int int64_t;
  35. # else
  36. __extension__
  37. typedef long long int int64_t;
  38. # endif
  39. #endif
  40. /* Unsigned. */
  41. typedef unsigned char uint8_t;
  42. typedef unsigned short int uint16_t;
  43. #ifndef __uint32_t_defined
  44. typedef unsigned int uint32_t;
  45. # define __uint32_t_defined
  46. #endif
  47. #if __WORDSIZE == 64
  48. typedef unsigned long int uint64_t;
  49. #else
  50. __extension__
  51. typedef unsigned long long int uint64_t;
  52. #endif
  53. /* Small types. */
  54. /* Signed. */
  55. typedef signed char int_least8_t;
  56. typedef short int int_least16_t;
  57. typedef int int_least32_t;
  58. #if __WORDSIZE == 64
  59. typedef long int int_least64_t;
  60. #else
  61. __extension__
  62. typedef long long int int_least64_t;
  63. #endif
  64. /* Unsigned. */
  65. typedef unsigned char uint_least8_t;
  66. typedef unsigned short int uint_least16_t;
  67. typedef unsigned int uint_least32_t;
  68. #if __WORDSIZE == 64
  69. typedef unsigned long int uint_least64_t;
  70. #else
  71. __extension__
  72. typedef unsigned long long int uint_least64_t;
  73. #endif
  74. /* Fast types. */
  75. /* Signed. */
  76. typedef signed char int_fast8_t;
  77. #if __WORDSIZE == 64
  78. typedef long int int_fast16_t;
  79. typedef long int int_fast32_t;
  80. typedef long int int_fast64_t;
  81. #else
  82. typedef int int_fast16_t;
  83. typedef int int_fast32_t;
  84. __extension__
  85. typedef long long int int_fast64_t;
  86. #endif
  87. /* Unsigned. */
  88. typedef unsigned char uint_fast8_t;
  89. #if __WORDSIZE == 64
  90. typedef unsigned long int uint_fast16_t;
  91. typedef unsigned long int uint_fast32_t;
  92. typedef unsigned long int uint_fast64_t;
  93. #else
  94. typedef unsigned int uint_fast16_t;
  95. typedef unsigned int uint_fast32_t;
  96. __extension__
  97. typedef unsigned long long int uint_fast64_t;
  98. #endif
  99. /* Types for `void *' pointers. */
  100. #if __WORDSIZE == 64
  101. # ifndef __intptr_t_defined
  102. typedef long int intptr_t;
  103. # define __intptr_t_defined
  104. # endif
  105. typedef unsigned long int uintptr_t;
  106. #else
  107. # ifndef __intptr_t_defined
  108. typedef int intptr_t;
  109. # define __intptr_t_defined
  110. # endif
  111. typedef unsigned int uintptr_t;
  112. #endif
  113. /* Largest integral types. */
  114. #if __WORDSIZE == 64
  115. typedef long int intmax_t;
  116. typedef unsigned long int uintmax_t;
  117. #else
  118. __extension__
  119. typedef long long int intmax_t;
  120. __extension__
  121. typedef unsigned long long int uintmax_t;
  122. #endif
  123. /* The ISO C99 standard specifies that in C++ implementations these
  124. macros should only be defined if explicitly requested. */
  125. #if !defined __cplusplus || defined __STDC_LIMIT_MACROS
  126. # if __WORDSIZE == 64
  127. # define __INT64_C(c) c ## L
  128. # define __UINT64_C(c) c ## UL
  129. # else
  130. # define __INT64_C(c) c ## LL
  131. # define __UINT64_C(c) c ## ULL
  132. # endif
  133. /* Limits of integral types. */
  134. /* Minimum of signed integral types. */
  135. # define INT8_MIN (-128)
  136. # define INT16_MIN (-32767-1)
  137. # define INT32_MIN (-2147483647-1)
  138. # define INT64_MIN (-__INT64_C(9223372036854775807)-1)
  139. /* Maximum of signed integral types. */
  140. # define INT8_MAX (127)
  141. # define INT16_MAX (32767)
  142. # define INT32_MAX (2147483647)
  143. # define INT64_MAX (__INT64_C(9223372036854775807))
  144. /* Maximum of unsigned integral types. */
  145. # define UINT8_MAX (255)
  146. # define UINT16_MAX (65535)
  147. # define UINT32_MAX (4294967295U)
  148. # define UINT64_MAX (__UINT64_C(18446744073709551615))
  149. /* Minimum of signed integral types having a minimum size. */
  150. # define INT_LEAST8_MIN (-128)
  151. # define INT_LEAST16_MIN (-32767-1)
  152. # define INT_LEAST32_MIN (-2147483647-1)
  153. # define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1)
  154. /* Maximum of signed integral types having a minimum size. */
  155. # define INT_LEAST8_MAX (127)
  156. # define INT_LEAST16_MAX (32767)
  157. # define INT_LEAST32_MAX (2147483647)
  158. # define INT_LEAST64_MAX (__INT64_C(9223372036854775807))
  159. /* Maximum of unsigned integral types having a minimum size. */
  160. # define UINT_LEAST8_MAX (255)
  161. # define UINT_LEAST16_MAX (65535)
  162. # define UINT_LEAST32_MAX (4294967295U)
  163. # define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615))
  164. /* Minimum of fast signed integral types having a minimum size. */
  165. # define INT_FAST8_MIN (-128)
  166. # if __WORDSIZE == 64
  167. # define INT_FAST16_MIN (-9223372036854775807L-1)
  168. # define INT_FAST32_MIN (-9223372036854775807L-1)
  169. # else
  170. # define INT_FAST16_MIN (-2147483647-1)
  171. # define INT_FAST32_MIN (-2147483647-1)
  172. # endif
  173. # define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1)
  174. /* Maximum of fast signed integral types having a minimum size. */
  175. # define INT_FAST8_MAX (127)
  176. # if __WORDSIZE == 64
  177. # define INT_FAST16_MAX (9223372036854775807L)
  178. # define INT_FAST32_MAX (9223372036854775807L)
  179. # else
  180. # define INT_FAST16_MAX (2147483647)
  181. # define INT_FAST32_MAX (2147483647)
  182. # endif
  183. # define INT_FAST64_MAX (__INT64_C(9223372036854775807))
  184. /* Maximum of fast unsigned integral types having a minimum size. */
  185. # define UINT_FAST8_MAX (255)
  186. # if __WORDSIZE == 64
  187. # define UINT_FAST16_MAX (18446744073709551615UL)
  188. # define UINT_FAST32_MAX (18446744073709551615UL)
  189. # else
  190. # define UINT_FAST16_MAX (4294967295U)
  191. # define UINT_FAST32_MAX (4294967295U)
  192. # endif
  193. # define UINT_FAST64_MAX (__UINT64_C(18446744073709551615))
  194. /* Values to test for integral types holding `void *' pointer. */
  195. # if __WORDSIZE == 64
  196. # define INTPTR_MIN (-9223372036854775807L-1)
  197. # define INTPTR_MAX (9223372036854775807L)
  198. # define UINTPTR_MAX (18446744073709551615UL)
  199. # else
  200. # define INTPTR_MIN (-2147483647-1)
  201. # define INTPTR_MAX (2147483647)
  202. # define UINTPTR_MAX (4294967295U)
  203. # endif
  204. #if !defined(__H8300H__) && !defined(__H8300S__)
  205. /* Minimum for largest signed integral type. */
  206. # define INTMAX_MIN (-__INT64_C(9223372036854775807)-1)
  207. /* Maximum for largest signed integral type. */
  208. # define INTMAX_MAX (__INT64_C(9223372036854775807))
  209. /* Maximum for largest unsigned integral type. */
  210. # define UINTMAX_MAX (__UINT64_C(18446744073709551615))
  211. #else
  212. /* Minimum for largest signed integral type. */
  213. # define INTMAX_MIN (-LONG_LONG_MAX-1)
  214. /* Maximum for largest signed integral type. */
  215. # define INTMAX_MAX (LONG_LONG_MAX)
  216. /* Maximum for largest unsigned integral type. */
  217. # define UINTMAX_MAX (LONG_LONG_MAX<<1+1)
  218. #endif
  219. /* Limits of other integer types. */
  220. /* Limits of `ptrdiff_t' type. */
  221. # if __WORDSIZE == 64
  222. # define PTRDIFF_MIN (-9223372036854775807L-1)
  223. # define PTRDIFF_MAX (9223372036854775807L)
  224. # else
  225. # define PTRDIFF_MIN (-2147483647-1)
  226. # define PTRDIFF_MAX (2147483647)
  227. # endif
  228. /* Limits of `sig_atomic_t'. */
  229. # define SIG_ATOMIC_MIN (-2147483647-1)
  230. # define SIG_ATOMIC_MAX (2147483647)
  231. /* Limit of `size_t' type. */
  232. # if __WORDSIZE == 64
  233. # define SIZE_MAX (18446744073709551615UL)
  234. # else
  235. # define SIZE_MAX (4294967295U)
  236. # endif
  237. #ifdef __UCLIBC_HAS_WCHAR__
  238. /* Limits of `wchar_t'. */
  239. # ifndef WCHAR_MIN
  240. /* These constants might also be defined in <wchar.h>. */
  241. # define WCHAR_MIN __WCHAR_MIN
  242. # define WCHAR_MAX __WCHAR_MAX
  243. # endif
  244. /* Limits of `wint_t'. */
  245. # define WINT_MIN (0u)
  246. # define WINT_MAX (4294967295u)
  247. #endif /* __UCLIBC_HAS_WCHAR__ */
  248. #endif /* C++ && limit macros */
  249. /* The ISO C99 standard specifies that in C++ implementations these
  250. should only be defined if explicitly requested. */
  251. #if !defined __cplusplus || defined __STDC_CONSTANT_MACROS
  252. /* Signed. */
  253. # define INT8_C(c) c
  254. # define INT16_C(c) c
  255. # define INT32_C(c) c
  256. # if __WORDSIZE == 64
  257. # define INT64_C(c) c ## L
  258. # else
  259. # define INT64_C(c) c ## LL
  260. # endif
  261. /* Unsigned. */
  262. # define UINT8_C(c) c ## U
  263. # define UINT16_C(c) c ## U
  264. # define UINT32_C(c) c ## U
  265. # if __WORDSIZE == 64
  266. # define UINT64_C(c) c ## UL
  267. # else
  268. # define UINT64_C(c) c ## ULL
  269. # endif
  270. /* Maximal type. */
  271. # if __WORDSIZE == 64
  272. # define INTMAX_C(c) c ## L
  273. # define UINTMAX_C(c) c ## UL
  274. # else
  275. # define INTMAX_C(c) c ## LL
  276. # define UINTMAX_C(c) c ## ULL
  277. # endif
  278. #endif /* C++ && constant macros */
  279. #endif /* stdint.h */