stdint.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* $OpenBSD: stdint.h,v 1.10 2015/04/30 18:19:25 millert 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 <machine/_types.h>
  21. #ifndef __BIT_TYPES_DEFINED__
  22. #define __BIT_TYPES_DEFINED__
  23. #endif
  24. /* 7.18.1.1 Exact-width integer types (also in sys/types.h) */
  25. #ifndef _INT8_T_DEFINED_
  26. #define _INT8_T_DEFINED_
  27. typedef __int8_t int8_t;
  28. #endif
  29. #ifndef _UINT8_T_DEFINED_
  30. #define _UINT8_T_DEFINED_
  31. typedef __uint8_t uint8_t;
  32. #endif
  33. #ifndef _INT16_T_DEFINED_
  34. #define _INT16_T_DEFINED_
  35. typedef __int16_t int16_t;
  36. #endif
  37. #ifndef _UINT16_T_DEFINED_
  38. #define _UINT16_T_DEFINED_
  39. typedef __uint16_t uint16_t;
  40. #endif
  41. #ifndef _INT32_T_DEFINED_
  42. #define _INT32_T_DEFINED_
  43. typedef __int32_t int32_t;
  44. #endif
  45. #ifndef _UINT32_T_DEFINED_
  46. #define _UINT32_T_DEFINED_
  47. typedef __uint32_t uint32_t;
  48. #endif
  49. #ifndef _INT64_T_DEFINED_
  50. #define _INT64_T_DEFINED_
  51. typedef __int64_t int64_t;
  52. #endif
  53. #ifndef _UINT64_T_DEFINED_
  54. #define _UINT64_T_DEFINED_
  55. typedef __uint64_t uint64_t;
  56. #endif
  57. /* 7.18.1.2 Minimum-width integer types */
  58. typedef __int_least8_t int_least8_t;
  59. typedef __uint_least8_t uint_least8_t;
  60. typedef __int_least16_t int_least16_t;
  61. typedef __uint_least16_t uint_least16_t;
  62. typedef __int_least32_t int_least32_t;
  63. typedef __uint_least32_t uint_least32_t;
  64. typedef __int_least64_t int_least64_t;
  65. typedef __uint_least64_t uint_least64_t;
  66. /* 7.18.1.3 Fastest minimum-width integer types */
  67. typedef __int_fast8_t int_fast8_t;
  68. typedef __uint_fast8_t uint_fast8_t;
  69. typedef __int_fast16_t int_fast16_t;
  70. typedef __uint_fast16_t uint_fast16_t;
  71. typedef __int_fast32_t int_fast32_t;
  72. typedef __uint_fast32_t uint_fast32_t;
  73. typedef __int_fast64_t int_fast64_t;
  74. typedef __uint_fast64_t uint_fast64_t;
  75. /* 7.18.1.4 Integer types capable of holding object pointers */
  76. #ifndef _INTPTR_T_DEFINED_
  77. #define _INTPTR_T_DEFINED_
  78. typedef __intptr_t intptr_t;
  79. #endif
  80. typedef __uintptr_t uintptr_t;
  81. /* 7.18.1.5 Greatest-width integer types */
  82. typedef __intmax_t intmax_t;
  83. typedef __uintmax_t uintmax_t;
  84. /*
  85. * 7.18.2 Limits of specified-width integer types.
  86. *
  87. * The following object-like macros specify the minimum and maximum limits
  88. * of integer types corresponding to the typedef names defined above.
  89. */
  90. /* 7.18.2.1 Limits of exact-width integer types */
  91. #define INT8_MIN (-0x7f - 1)
  92. #define INT16_MIN (-0x7fff - 1)
  93. #define INT32_MIN (-0x7fffffff - 1)
  94. #define INT64_MIN (-0x7fffffffffffffffLL - 1)
  95. #define INT8_MAX 0x7f
  96. #define INT16_MAX 0x7fff
  97. #define INT32_MAX 0x7fffffff
  98. #define INT64_MAX 0x7fffffffffffffffLL
  99. #define UINT8_MAX 0xff
  100. #define UINT16_MAX 0xffff
  101. #define UINT32_MAX 0xffffffffU
  102. #define UINT64_MAX 0xffffffffffffffffULL
  103. /* 7.18.2.2 Limits of minimum-width integer types */
  104. #define INT_LEAST8_MIN INT8_MIN
  105. #define INT_LEAST16_MIN INT16_MIN
  106. #define INT_LEAST32_MIN INT32_MIN
  107. #define INT_LEAST64_MIN INT64_MIN
  108. #define INT_LEAST8_MAX INT8_MAX
  109. #define INT_LEAST16_MAX INT16_MAX
  110. #define INT_LEAST32_MAX INT32_MAX
  111. #define INT_LEAST64_MAX INT64_MAX
  112. #define UINT_LEAST8_MAX UINT8_MAX
  113. #define UINT_LEAST16_MAX UINT16_MAX
  114. #define UINT_LEAST32_MAX UINT32_MAX
  115. #define UINT_LEAST64_MAX UINT64_MAX
  116. /* 7.18.2.3 Limits of fastest minimum-width integer types */
  117. #define INT_FAST8_MIN __INT_FAST8_MIN
  118. #define INT_FAST16_MIN __INT_FAST16_MIN
  119. #define INT_FAST32_MIN __INT_FAST32_MIN
  120. #define INT_FAST64_MIN __INT_FAST64_MIN
  121. #define INT_FAST8_MAX __INT_FAST8_MAX
  122. #define INT_FAST16_MAX __INT_FAST16_MAX
  123. #define INT_FAST32_MAX __INT_FAST32_MAX
  124. #define INT_FAST64_MAX __INT_FAST64_MAX
  125. #define UINT_FAST8_MAX __UINT_FAST8_MAX
  126. #define UINT_FAST16_MAX __UINT_FAST16_MAX
  127. #define UINT_FAST32_MAX __UINT_FAST32_MAX
  128. #define UINT_FAST64_MAX __UINT_FAST64_MAX
  129. /* 7.18.2.4 Limits of integer types capable of holding object pointers */
  130. #ifdef __LP64__
  131. #define INTPTR_MIN (-0x7fffffffffffffffL - 1)
  132. #define INTPTR_MAX 0x7fffffffffffffffL
  133. #define UINTPTR_MAX 0xffffffffffffffffUL
  134. #else
  135. #define INTPTR_MIN (-0x7fffffffL - 1)
  136. #define INTPTR_MAX 0x7fffffffL
  137. #define UINTPTR_MAX 0xffffffffUL
  138. #endif
  139. /* 7.18.2.5 Limits of greatest-width integer types */
  140. #define INTMAX_MIN INT64_MIN
  141. #define INTMAX_MAX INT64_MAX
  142. #define UINTMAX_MAX UINT64_MAX
  143. /*
  144. * 7.18.3 Limits of other integer types.
  145. *
  146. * The following object-like macros specify the minimum and maximum limits
  147. * of integer types corresponding to types specified in other standard
  148. * header files.
  149. */
  150. /* Limits of ptrdiff_t */
  151. #define PTRDIFF_MIN INTPTR_MIN
  152. #define PTRDIFF_MAX INTPTR_MAX
  153. /* Limits of sig_atomic_t */
  154. #define SIG_ATOMIC_MIN INT32_MIN
  155. #define SIG_ATOMIC_MAX INT32_MAX
  156. /* Limit of size_t */
  157. #ifndef SIZE_MAX
  158. #define SIZE_MAX UINTPTR_MAX
  159. #endif
  160. /* Limits of wchar_t */
  161. #ifndef WCHAR_MIN
  162. #define WCHAR_MIN INT32_MIN
  163. #endif
  164. #ifndef WCHAR_MAX
  165. #define WCHAR_MAX INT32_MAX
  166. #endif
  167. /* Limits of wint_t */
  168. #define WINT_MIN INT32_MIN
  169. #define WINT_MAX INT32_MAX
  170. /*
  171. * 7.18.4 Macros for integer constants.
  172. *
  173. * The following function-like macros expand to integer constants
  174. * suitable for initializing objects that have integer types corresponding
  175. * to types defined in <stdint.h>. The argument in any instance of
  176. * these macros shall be a decimal, octal, or hexadecimal constant with
  177. * a value that does not exceed the limits for the corresponding type.
  178. */
  179. /* 7.18.4.1 Macros for minimum-width integer constants. */
  180. #define INT8_C(_c) (_c)
  181. #define INT16_C(_c) (_c)
  182. #define INT32_C(_c) (_c)
  183. #define INT64_C(_c) __CONCAT(_c, LL)
  184. #define UINT8_C(_c) (_c)
  185. #define UINT16_C(_c) (_c)
  186. #define UINT32_C(_c) __CONCAT(_c, U)
  187. #define UINT64_C(_c) __CONCAT(_c, ULL)
  188. /* 7.18.4.2 Macros for greatest-width integer constants. */
  189. #define INTMAX_C(_c) __CONCAT(_c, LL)
  190. #define UINTMAX_C(_c) __CONCAT(_c, ULL)
  191. #endif /* _SYS_STDINT_H_ */