stdint.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /* Copyright (C) 1997, 1998, 1999 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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. /*
  16. * ISO C 9X: 7.18 Integer types <stdint.h>
  17. */
  18. #ifndef _STDINT_H
  19. #define _STDINT_H 1
  20. #include <features.h>
  21. #define __need_wchar_t
  22. #include <stddef.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. typedef unsigned int uint32_t;
  43. #if __WORDSIZE == 64
  44. typedef unsigned long int uint64_t;
  45. #else
  46. __extension__
  47. typedef unsigned long long int uint64_t;
  48. #endif
  49. /* Small types. */
  50. /* Signed. */
  51. typedef signed char int_least8_t;
  52. typedef short int int_least16_t;
  53. typedef int int_least32_t;
  54. #if __WORDSIZE == 64
  55. typedef long int int_least64_t;
  56. #else
  57. __extension__
  58. typedef long long int int_least64_t;
  59. #endif
  60. /* Unsigned. */
  61. typedef unsigned char uint_least8_t;
  62. typedef unsigned short int uint_least16_t;
  63. typedef unsigned int uint_least32_t;
  64. #if __WORDSIZE == 64
  65. typedef unsigned long int uint_least64_t;
  66. #else
  67. __extension__
  68. typedef unsigned long long int uint_least64_t;
  69. #endif
  70. /* Fast types. */
  71. /* Signed. */
  72. typedef signed char int_fast8_t;
  73. #if __WORDSIZE == 64
  74. typedef long int int_fast16_t;
  75. typedef long int int_fast32_t;
  76. typedef long int int_fast64_t;
  77. #else
  78. typedef int int_fast16_t;
  79. typedef int int_fast32_t;
  80. __extension__
  81. typedef long long int int_fast64_t;
  82. #endif
  83. /* Unsigned. */
  84. typedef unsigned char uint_fast8_t;
  85. #if __WORDSIZE == 64
  86. typedef unsigned long int uint_fast16_t;
  87. typedef unsigned long int uint_fast32_t;
  88. typedef unsigned long int uint_fast64_t;
  89. #else
  90. typedef unsigned int uint_fast16_t;
  91. typedef unsigned int uint_fast32_t;
  92. __extension__
  93. typedef unsigned long long int uint_fast64_t;
  94. #endif
  95. /* Types for `void *' pointers. */
  96. #if __WORDSIZE == 64
  97. # ifndef intptr_t
  98. typedef long int intptr_t;
  99. # define intptr_t intptr_t
  100. # endif
  101. typedef unsigned long int uintptr_t;
  102. #else
  103. # ifndef intptr_t
  104. typedef int intptr_t;
  105. # define intptr_t intptr_t
  106. # endif
  107. typedef unsigned int uintptr_t;
  108. #endif
  109. /* Largest integral types. */
  110. #if __WORDSIZE == 64
  111. typedef long int intmax_t;
  112. typedef unsigned long int uintmax_t;
  113. #else
  114. __extension__
  115. typedef long long int intmax_t;
  116. __extension__
  117. typedef unsigned long long int uintmax_t;
  118. #endif
  119. /* The ISO C 9X standard specifies that in C++ implementations these
  120. macros should only be defined if explicitly requested. */
  121. #if !defined __cplusplus || defined __STDC_LIMIT_MACROS
  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 (255U)
  142. # define UINT16_MAX (65535U)
  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 (255U)
  157. # define UINT_LEAST16_MAX (65535U)
  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 (255U)
  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. /* Limits of `wchar_t'. */
  225. # ifndef WCHAR_MIN
  226. /* These constants might also be defined in <wchar.h>. */
  227. # define WCHAR_MIN (0)
  228. # define WCHAR_MAX (2147483647)
  229. # endif
  230. /* Limits of `wint_t'. */
  231. # define WINT_MIN (0)
  232. # define WINT_MAX (2147483647)
  233. #endif /* C++ && limit macros */
  234. /* The ISO C 9X standard specifies that in C++ implementations these
  235. should only be defined if explicitly requested. */
  236. #if !defined __cplusplus || defined __STDC_CONSTANT_MACROS
  237. /* Signed. */
  238. # define INT8_C(c) c
  239. # define INT16_C(c) c
  240. # define INT32_C(c) c
  241. # if __WORDSIZE == 64
  242. # define INT64_C(c) c ## L
  243. # else
  244. # define INT64_C(c) c ## LL
  245. # endif
  246. /* Unsigned. */
  247. # define UINT8_C(c) c ## U
  248. # define UINT16_C(c) c ## U
  249. # define UINT32_C(c) c ## U
  250. # if __WORDSIZE == 64
  251. # define UINT64_C(c) c ## UL
  252. # else
  253. # define UINT64_C(c) c ## ULL
  254. # endif
  255. /* Maximal type. */
  256. # if __WORDSIZE == 64
  257. # define INTMAX_C(c) c ## L
  258. # define UINTMAX_C(c) c ## UL
  259. # else
  260. # define INTMAX_C(c) c ## LL
  261. # define UINTMAX_C(c) c ## ULL
  262. # endif
  263. #endif /* C++ && constant macros */
  264. #endif /* stdint.h */