stdint.h 8.4 KB

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