stdint.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /* $OpenBSD: stdint.h,v 1.4 2006/12/10 22:17:55 deraadt Exp $ */
  2. /*
  3. * Copyright (c) 1997, 2005 Todd C. Miller <Todd.Miller@courtesan.com>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _SYS_STDINT_H_
  18. #define _SYS_STDINT_H_
  19. #include <sys/cdefs.h>
  20. #include <sys/_types.h>
  21. /* 7.18.1.1 Exact-width integer types (also in sys/types.h) */
  22. #ifndef _INT8_T_DEFINED_
  23. #define _INT8_T_DEFINED_
  24. typedef __int8_t int8_t;
  25. #endif
  26. #ifndef _UINT8_T_DEFINED_
  27. #define _UINT8_T_DEFINED_
  28. typedef __uint8_t uint8_t;
  29. #endif
  30. #ifndef _INT16_T_DEFINED_
  31. #define _INT16_T_DEFINED_
  32. typedef __int16_t int16_t;
  33. #endif
  34. #ifndef _UINT16_T_DEFINED_
  35. #define _UINT16_T_DEFINED_
  36. typedef __uint16_t uint16_t;
  37. #endif
  38. #ifndef _INT32_T_DEFINED_
  39. #define _INT32_T_DEFINED_
  40. typedef __int32_t int32_t;
  41. #endif
  42. #ifndef _UINT32_T_DEFINED_
  43. #define _UINT32_T_DEFINED_
  44. typedef __uint32_t uint32_t;
  45. #endif
  46. #ifndef _INT64_T_DEFINED_
  47. #define _INT64_T_DEFINED_
  48. typedef __int64_t int64_t;
  49. #endif
  50. #ifndef _UINT64_T_DEFINED_
  51. #define _UINT64_T_DEFINED_
  52. typedef __uint64_t uint64_t;
  53. #endif
  54. /* 7.18.1.2 Minimum-width integer types */
  55. typedef __int_least8_t int_least8_t;
  56. typedef __uint_least8_t uint_least8_t;
  57. typedef __int_least16_t int_least16_t;
  58. typedef __uint_least16_t uint_least16_t;
  59. typedef __int_least32_t int_least32_t;
  60. typedef __uint_least32_t uint_least32_t;
  61. typedef __int_least64_t int_least64_t;
  62. typedef __uint_least64_t uint_least64_t;
  63. /* 7.18.1.3 Fastest minimum-width integer types */
  64. typedef __int_fast8_t int_fast8_t;
  65. typedef __uint_fast8_t uint_fast8_t;
  66. typedef __int_fast16_t int_fast16_t;
  67. typedef __uint_fast16_t uint_fast16_t;
  68. typedef __int_fast32_t int_fast32_t;
  69. typedef __uint_fast32_t uint_fast32_t;
  70. typedef __int_fast64_t int_fast64_t;
  71. typedef __uint_fast64_t uint_fast64_t;
  72. /* 7.18.1.4 Integer types capable of holding object pointers */
  73. #ifndef _INTPTR_T_DEFINED_
  74. #define _INTPTR_T_DEFINED_
  75. typedef __intptr_t intptr_t;
  76. #endif
  77. #ifndef _UINTPTR_T_DEFINED_
  78. #define _UINTPTR_T_DEFINED_
  79. typedef __uintptr_t uintptr_t;
  80. #endif
  81. /* 7.18.1.5 Greatest-width integer types */
  82. typedef __intmax_t intmax_t;
  83. typedef __uintmax_t uintmax_t;
  84. //#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
  85. /*
  86. * 7.18.2 Limits of specified-width integer types.
  87. *
  88. * The following object-like macros specify the minimum and maximum limits
  89. * of integer types corresponding to the typedef names defined above.
  90. */
  91. /* 7.18.2.1 Limits of exact-width integer types */
  92. #define INT8_MIN (-0x7f - 1)
  93. #define INT16_MIN (-0x7fff - 1)
  94. #define INT32_MIN (-0x7fffffff - 1)
  95. #ifdef __x86_64__
  96. #define INT64_MIN (-0x7fffffffffffffffL - 1)
  97. #else
  98. #define INT64_MIN (-0x7fffffffffffffffLL - 1)
  99. #endif
  100. #define INT8_MAX 0x7f
  101. #define INT16_MAX 0x7fff
  102. #define INT32_MAX 0x7fffffff
  103. #ifdef __x86_64__
  104. #define INT64_MAX 0x7fffffffffffffffL
  105. #else
  106. #define INT64_MAX 0x7fffffffffffffffLL
  107. #endif
  108. #define UINT8_MAX 0xff
  109. #define UINT16_MAX 0xffff
  110. #define UINT32_MAX 0xffffffffU
  111. #ifdef __x86_64__
  112. #define UINT64_MAX 0xffffffffffffffffUL
  113. #else
  114. #define UINT64_MAX 0xffffffffffffffffULL
  115. #endif
  116. /* 7.18.2.2 Limits of minimum-width integer types */
  117. #define INT_LEAST8_MIN INT8_MIN
  118. #define INT_LEAST16_MIN INT16_MIN
  119. #define INT_LEAST32_MIN INT32_MIN
  120. #define INT_LEAST64_MIN INT64_MIN
  121. #define INT_LEAST8_MAX INT8_MAX
  122. #define INT_LEAST16_MAX INT16_MAX
  123. #define INT_LEAST32_MAX INT32_MAX
  124. #define INT_LEAST64_MAX INT64_MAX
  125. #define UINT_LEAST8_MAX UINT8_MAX
  126. #define UINT_LEAST16_MAX UINT16_MAX
  127. #define UINT_LEAST32_MAX UINT32_MAX
  128. #define UINT_LEAST64_MAX UINT64_MAX
  129. /* 7.18.2.3 Limits of fastest minimum-width integer types */
  130. #define INT_FAST8_MIN INT8_MIN
  131. #define INT_FAST16_MIN INT16_MIN
  132. #define INT_FAST32_MIN INT32_MIN
  133. #define INT_FAST64_MIN INT64_MIN
  134. #define INT_FAST8_MAX INT8_MAX
  135. #ifdef __x86_64__
  136. #define INT_FAST16_MAX INT64_MAX
  137. #define INT_FAST32_MAX INT64_MAX
  138. #else
  139. #define INT_FAST16_MAX INT32_MAX
  140. #define INT_FAST32_MAX INT32_MAX
  141. #endif
  142. #define INT_FAST64_MAX INT64_MAX
  143. #define UINT_FAST8_MAX UINT8_MAX
  144. #ifdef __x86_64__
  145. #define UINT_FAST16_MAX UINT64_MAX
  146. #define UINT_FAST32_MAX UINT64_MAX
  147. #else
  148. #define UINT_FAST16_MAX UINT32_MAX
  149. #define UINT_FAST32_MAX UINT32_MAX
  150. #endif
  151. #define UINT_FAST64_MAX UINT64_MAX
  152. /* 7.18.2.4 Limits of integer types capable of holding object pointers */
  153. #ifdef __x86_64__
  154. #define INTPTR_MIN INT64_MIN
  155. #define INTPTR_MAX INT64_MAX
  156. #define UINTPTR_MAX UINT64_MAX
  157. #else
  158. #define INTPTR_MIN INT32_MIN
  159. #define INTPTR_MAX INT32_MAX
  160. #define UINTPTR_MAX UINT32_MAX
  161. #endif
  162. /* 7.18.2.5 Limits of greatest-width integer types */
  163. #define INTMAX_MIN INT64_MIN
  164. #define INTMAX_MAX INT64_MAX
  165. #define UINTMAX_MAX UINT64_MAX
  166. /*
  167. * 7.18.3 Limits of other integer types.
  168. *
  169. * The following object-like macros specify the minimum and maximum limits
  170. * of integer types corresponding to types specified in other standard
  171. * header files.
  172. */
  173. /* Limits of ptrdiff_t */
  174. #define PTRDIFF_MIN INTPTR_MIN
  175. #define PTRDIFF_MAX INTPTR_MAX
  176. /* Limits of size_t (also in limits.h) */
  177. #ifndef SIZE_MAX
  178. #define SIZE_MAX UINTPTR_MAX
  179. #endif
  180. /* Limits of wchar_t */
  181. # ifdef __WCHAR_MAX__
  182. # define WCHAR_MAX __WCHAR_MAX__
  183. # else
  184. # define WCHAR_MAX (2147483647)
  185. # endif
  186. # ifdef __WCHAR_MIN__
  187. # define WCHAR_MIN __WCHAR_MIN__
  188. # elif L'\0' - 1 > 0
  189. # define WCHAR_MIN L'\0'
  190. # else
  191. # define WCHAR_MIN (-WCHAR_MAX - 1)
  192. # endif
  193. /* Limits of wint_t */
  194. # define WINT_MIN (0u)
  195. # define WINT_MAX (4294967295u)
  196. //#endif /* __cplusplus || __STDC_LIMIT_MACROS */
  197. //#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
  198. /*
  199. * 7.18.4 Macros for integer constants.
  200. *
  201. * The following function-like macros expand to integer constants
  202. * suitable for initializing objects that have integer types corresponding
  203. * to types defined in <stdint.h>. The argument in any instance of
  204. * these macros shall be a decimal, octal, or hexadecimal constant with
  205. * a value that does not exceed the limits for the corresponding type.
  206. */
  207. /* 7.18.4.1 Macros for minimum-width integer constants. */
  208. #define INT8_C(_c) (_c)
  209. #define INT16_C(_c) (_c)
  210. #define INT32_C(_c) (_c)
  211. #define INT64_C(_c) __CONCAT(_c, LL)
  212. #define UINT8_C(_c) (_c)
  213. #define UINT16_C(_c) (_c)
  214. #define UINT32_C(_c) __CONCAT(_c, U)
  215. #define UINT64_C(_c) __CONCAT(_c, ULL)
  216. /* 7.18.4.2 Macros for greatest-width integer constants. */
  217. #define INTMAX_C(_c) __CONCAT(_c, LL)
  218. #define UINTMAX_C(_c) __CONCAT(_c, ULL)
  219. //#endif /* __cplusplus || __STDC_CONSTANT_MACROS */
  220. #endif /* _SYS_STDINT_H_ */