_stdint.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*-
  2. * SPDX-License-Identifier: BSD-4-Clause
  3. *
  4. * Copyright (c) 2001, 2002 Mike Barcroft <mike@FreeBSD.org>
  5. * Copyright (c) 2001 The NetBSD Foundation, Inc.
  6. * All rights reserved.
  7. *
  8. * This code is derived from software contributed to The NetBSD Foundation
  9. * by Klaus Klein.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. All advertising materials mentioning features or use of this software
  20. * must display the following acknowledgement:
  21. * This product includes software developed by the NetBSD
  22. * Foundation, Inc. and its contributors.
  23. * 4. Neither the name of The NetBSD Foundation nor the names of its
  24. * contributors may be used to endorse or promote products derived
  25. * from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  28. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  29. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  31. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * $FreeBSD$
  40. */
  41. #ifndef _MACHINE__STDINT_H_
  42. #define _MACHINE__STDINT_H_
  43. #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
  44. #define INT8_C(c) (c)
  45. #define INT16_C(c) (c)
  46. #define INT32_C(c) (c)
  47. #define UINT8_C(c) (c)
  48. #define UINT16_C(c) (c)
  49. #define UINT32_C(c) (c ## U)
  50. #ifdef __LP64__
  51. #define INT64_C(c) (c ## L)
  52. #define UINT64_C(c) (c ## UL)
  53. #else
  54. #define INT64_C(c) (c ## LL)
  55. #define UINT64_C(c) (c ## ULL)
  56. #endif
  57. #define INTMAX_C(c) INT64_C(c)
  58. #define UINTMAX_C(c) UINT64_C(c)
  59. #endif /* !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) */
  60. #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
  61. #ifndef __INT64_C
  62. #ifdef __LP64__
  63. #define __INT64_C(c) (c ## L)
  64. #define __UINT64_C(c) (c ## UL)
  65. #else
  66. #define __INT64_C(c) (c ## LL)
  67. #define __UINT64_C(c) (c ## ULL)
  68. #endif
  69. #endif
  70. /*
  71. * ISO/IEC 9899:1999
  72. * 7.18.2.1 Limits of exact-width integer types
  73. */
  74. /* Minimum values of exact-width signed integer types. */
  75. #define INT8_MIN (-0x7f-1)
  76. #define INT16_MIN (-0x7fff-1)
  77. #define INT32_MIN (-0x7fffffff-1)
  78. #define INT64_MIN (-__INT64_C(0x7fffffffffffffff)-1)
  79. /* Maximum values of exact-width signed integer types. */
  80. #define INT8_MAX 0x7f
  81. #define INT16_MAX 0x7fff
  82. #define INT32_MAX 0x7fffffff
  83. #define INT64_MAX __INT64_C(0x7fffffffffffffff)
  84. /* Maximum values of exact-width unsigned integer types. */
  85. #define UINT8_MAX 0xff
  86. #define UINT16_MAX 0xffff
  87. #define UINT32_MAX 0xffffffff
  88. #define UINT64_MAX __UINT64_C(0xffffffffffffffff)
  89. /*
  90. * ISO/IEC 9899:1999
  91. * 7.18.2.2 Limits of minimum-width integer types
  92. */
  93. /* Minimum values of minimum-width signed integer types. */
  94. #define INT_LEAST8_MIN INT8_MIN
  95. #define INT_LEAST16_MIN INT16_MIN
  96. #define INT_LEAST32_MIN INT32_MIN
  97. #define INT_LEAST64_MIN INT64_MIN
  98. /* Maximum values of minimum-width signed integer types. */
  99. #define INT_LEAST8_MAX INT8_MAX
  100. #define INT_LEAST16_MAX INT16_MAX
  101. #define INT_LEAST32_MAX INT32_MAX
  102. #define INT_LEAST64_MAX INT64_MAX
  103. /* Maximum values of minimum-width unsigned integer types. */
  104. #define UINT_LEAST8_MAX UINT8_MAX
  105. #define UINT_LEAST16_MAX UINT16_MAX
  106. #define UINT_LEAST32_MAX UINT32_MAX
  107. #define UINT_LEAST64_MAX UINT64_MAX
  108. /*
  109. * ISO/IEC 9899:1999
  110. * 7.18.2.3 Limits of fastest minimum-width integer types
  111. */
  112. /* Minimum values of fastest minimum-width signed integer types. */
  113. #define INT_FAST8_MIN INT32_MIN
  114. #define INT_FAST16_MIN INT32_MIN
  115. #define INT_FAST32_MIN INT32_MIN
  116. #define INT_FAST64_MIN INT64_MIN
  117. /* Maximum values of fastest minimum-width signed integer types. */
  118. #define INT_FAST8_MAX INT32_MAX
  119. #define INT_FAST16_MAX INT32_MAX
  120. #define INT_FAST32_MAX INT32_MAX
  121. #define INT_FAST64_MAX INT64_MAX
  122. /* Maximum values of fastest minimum-width unsigned integer types. */
  123. #define UINT_FAST8_MAX UINT32_MAX
  124. #define UINT_FAST16_MAX UINT32_MAX
  125. #define UINT_FAST32_MAX UINT32_MAX
  126. #define UINT_FAST64_MAX UINT64_MAX
  127. /*
  128. * ISO/IEC 9899:1999
  129. * 7.18.2.4 Limits of integer types capable of holding object pointers
  130. */
  131. #ifdef __LP64__
  132. #define INTPTR_MIN INT64_MIN
  133. #define INTPTR_MAX INT64_MAX
  134. #define UINTPTR_MAX UINT64_MAX
  135. #else
  136. #define INTPTR_MIN INT32_MIN
  137. #define INTPTR_MAX INT32_MAX
  138. #define UINTPTR_MAX UINT32_MAX
  139. #endif
  140. /*
  141. * ISO/IEC 9899:1999
  142. * 7.18.2.5 Limits of greatest-width integer types
  143. */
  144. #define INTMAX_MIN INT64_MIN
  145. #define INTMAX_MAX INT64_MAX
  146. #define UINTMAX_MAX UINT64_MAX
  147. /*
  148. * ISO/IEC 9899:1999
  149. * 7.18.3 Limits of other integer types
  150. */
  151. #ifdef __LP64__
  152. /* Limits of ptrdiff_t. */
  153. #define PTRDIFF_MIN INT64_MIN
  154. #define PTRDIFF_MAX INT64_MAX
  155. /* Limits of sig_atomic_t. */
  156. #define SIG_ATOMIC_MIN INT64_MIN
  157. #define SIG_ATOMIC_MAX INT64_MAX
  158. /* Limit of size_t. */
  159. #define SIZE_MAX UINT64_MAX
  160. #else
  161. /* Limits of ptrdiff_t. */
  162. #define PTRDIFF_MIN INT32_MIN
  163. #define PTRDIFF_MAX INT32_MAX
  164. /* Limits of sig_atomic_t. */
  165. #define SIG_ATOMIC_MIN INT32_MIN
  166. #define SIG_ATOMIC_MAX INT32_MAX
  167. /* Limit of size_t. */
  168. #define SIZE_MAX UINT32_MAX
  169. #endif
  170. /* Limits of wint_t. */
  171. #define WINT_MIN INT32_MIN
  172. #define WINT_MAX INT32_MAX
  173. #endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
  174. #endif /* !_MACHINE__STDINT_H_ */