_intsup.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (c) 2004, 2005 by
  3. * Ralf Corsepius, Ulm/Germany. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and distribute this software
  6. * is freely granted, provided that this notice is preserved.
  7. */
  8. #ifndef _SYS__INTSUP_H
  9. #define _SYS__INTSUP_H
  10. #include <sys/features.h>
  11. #if __GNUC_PREREQ (3, 2)
  12. /* gcc > 3.2 implicitly defines the values we are interested */
  13. #define __STDINT_EXP(x) __##x##__
  14. #else
  15. #define __STDINT_EXP(x) x
  16. #include <limits.h>
  17. #endif
  18. /* Determine how intptr_t and intN_t fastN_t and leastN_t are defined by gcc
  19. for this target. This is used to determine the correct printf() constant in
  20. inttypes.h and other constants in stdint.h.
  21. So we end up with
  22. ?(signed|unsigned) char == 0
  23. ?(signed|unsigned) short == 1
  24. ?(signed|unsigned) int == 2
  25. ?(signed|unsigned) short int == 3
  26. ?(signed|unsigned) long == 4
  27. ?(signed|unsigned) long int == 6
  28. ?(signed|unsigned) long long == 8
  29. ?(signed|unsigned) long long int == 10
  30. */
  31. #pragma push_macro("signed")
  32. #pragma push_macro("unsigned")
  33. #pragma push_macro("char")
  34. #pragma push_macro("short")
  35. #pragma push_macro("__int20")
  36. #pragma push_macro("int")
  37. #pragma push_macro("long")
  38. #undef signed
  39. #undef unsigned
  40. #undef char
  41. #undef short
  42. #undef int
  43. #undef __int20
  44. #undef long
  45. #define signed +0
  46. #define unsigned +0
  47. #define char +0
  48. #define short +1
  49. #define __int20 +2
  50. #define int +2
  51. #define long +4
  52. #if (__INTPTR_TYPE__ == 8 || __INTPTR_TYPE__ == 10)
  53. #define _INTPTR_EQ_LONGLONG
  54. #elif (__INTPTR_TYPE__ == 4 || __INTPTR_TYPE__ == 6)
  55. #define _INTPTR_EQ_LONG
  56. /* Note - the tests for _INTPTR_EQ_INT and _INTPTR_EQ_SHORT are currently
  57. redundant as the values are not used. But one day they may be needed
  58. and so the tests remain. */
  59. #elif __INTPTR_TYPE__ == 2
  60. #define _INTPTR_EQ_INT
  61. #elif (__INTPTR_TYPE__ == 1 || __INTPTR_TYPE__ == 3)
  62. #define _INTPTR_EQ_SHORT
  63. #else
  64. #error "Unable to determine type definition of intptr_t"
  65. #endif
  66. #if (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6)
  67. #define _INT32_EQ_LONG
  68. #elif __INT32_TYPE__ == 2
  69. /* Nothing to define because int32_t is safe to print as an int. */
  70. #else
  71. #error "Unable to determine type definition of int32_t"
  72. #endif
  73. #if (__INT8_TYPE__ == 0)
  74. #define __INT8 "hh"
  75. #elif (__INT8_TYPE__ == 1 || __INT8_TYPE__ == 3)
  76. #define __INT8 "h"
  77. #elif (__INT8_TYPE__ == 2)
  78. #define __INT8
  79. #elif (__INT8_TYPE__ == 4 || __INT8_TYPE__ == 6)
  80. #define __INT8 "l"
  81. #elif (__INT8_TYPE__ == 8 || __INT8_TYPE__ == 10)
  82. #define __INT8 "ll"
  83. #endif
  84. #if (__INT16_TYPE__ == 1 || __INT16_TYPE__ == 3)
  85. #define __INT16 "h"
  86. #elif (__INT16_TYPE__ == 2)
  87. #define __INT16
  88. #elif (__INT16_TYPE__ == 4 || __INT16_TYPE__ == 6)
  89. #define __INT16 "l"
  90. #elif (__INT16_TYPE__ == 8 || __INT16_TYPE__ == 10)
  91. #define __INT16 "ll"
  92. #endif
  93. #if (__INT32_TYPE__ == 2)
  94. #define __INT32
  95. #elif (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6)
  96. #define __INT32 "l"
  97. #elif (__INT32_TYPE__ == 8 || __INT32_TYPE__ == 10)
  98. #define __INT32 "ll"
  99. #endif
  100. #if (__INT64_TYPE__ == 2)
  101. #define __INT64
  102. #elif (__INT64_TYPE__ == 4 || __INT64_TYPE__ == 6)
  103. #define __INT64 "l"
  104. #elif (__INT64_TYPE__ == 8 || __INT64_TYPE__ == 10)
  105. #define __INT64 "ll"
  106. #endif
  107. #if (__INT_FAST8_TYPE__ == 0)
  108. #define __FAST8 "hh"
  109. #elif (__INT_FAST8_TYPE__ == 1 || __INT_FAST8_TYPE__ == 3)
  110. #define __FAST8 "h"
  111. #elif (__INT_FAST8_TYPE__ == 2)
  112. #define __FAST8
  113. #elif (__INT_FAST8_TYPE__ == 4 || __INT_FAST8_TYPE__ == 6)
  114. #define __FAST8 "l"
  115. #elif (__INT_FAST8_TYPE__ == 8 || __INT_FAST8_TYPE__ == 10)
  116. #define __FAST8 "ll"
  117. #endif
  118. #if (__INT_FAST16_TYPE__ == 1 || __INT_FAST16_TYPE__ == 3)
  119. #define __FAST16 "h"
  120. #elif (__INT_FAST16_TYPE__ == 2)
  121. #define __FAST16
  122. #elif (__INT_FAST16_TYPE__ == 4 || __INT_FAST16_TYPE__ == 6)
  123. #define __FAST16 "l"
  124. #elif (__INT_FAST16_TYPE__ == 8 || __INT_FAST16_TYPE__ == 10)
  125. #define __FAST16 "ll"
  126. #endif
  127. #if (__INT_FAST32_TYPE__ == 2)
  128. #define __FAST32
  129. #elif (__INT_FAST32_TYPE__ == 4 || __INT_FAST32_TYPE__ == 6)
  130. #define __FAST32 "l"
  131. #elif (__INT_FAST32_TYPE__ == 8 || __INT_FAST32_TYPE__ == 10)
  132. #define __FAST32 "ll"
  133. #endif
  134. #if (__INT_FAST64_TYPE__ == 2)
  135. #define __FAST64
  136. #elif (__INT_FAST64_TYPE__ == 4 || __INT_FAST64_TYPE__ == 6)
  137. #define __FAST64 "l"
  138. #elif (__INT_FAST64_TYPE__ == 8 || __INT_FAST64_TYPE__ == 10)
  139. #define __FAST64 "ll"
  140. #endif
  141. #if (__INT_LEAST8_TYPE__ == 0)
  142. #define __LEAST8 "hh"
  143. #elif (__INT_LEAST8_TYPE__ == 1 || __INT_LEAST8_TYPE__ == 3)
  144. #define __LEAST8 "h"
  145. #elif (__INT_LEAST8_TYPE__ == 2)
  146. #define __LEAST8
  147. #elif (__INT_LEAST8_TYPE__ == 4 || __INT_LEAST8_TYPE__ == 6)
  148. #define __LEAST8 "l"
  149. #elif (__INT_LEAST8_TYPE__ == 8 || __INT_LEAST8_TYPE__ == 10)
  150. #define __LEAST8 "ll"
  151. #endif
  152. #if (__INT_LEAST16_TYPE__ == 1 || __INT_LEAST16_TYPE__ == 3)
  153. #define __LEAST16 "h"
  154. #elif (__INT_LEAST16_TYPE__ == 2)
  155. #define __LEAST16
  156. #elif (__INT_LEAST16_TYPE__ == 4 || __INT_LEAST16_TYPE__ == 6)
  157. #define __LEAST16 "l"
  158. #elif (__INT_LEAST16_TYPE__ == 8 || __INT_LEAST16_TYPE__ == 10)
  159. #define __LEAST16 "ll"
  160. #endif
  161. #if (__INT_LEAST32_TYPE__ == 2)
  162. #define __LEAST32
  163. #elif (__INT_LEAST32_TYPE__ == 4 || __INT_LEAST32_TYPE__ == 6)
  164. #define __LEAST32 "l"
  165. #elif (__INT_LEAST32_TYPE__ == 8 || __INT_LEAST32_TYPE__ == 10)
  166. #define __LEAST32 "ll"
  167. #endif
  168. #if (__INT_LEAST64_TYPE__ == 2)
  169. #define __LEAST64
  170. #elif (__INT_LEAST64_TYPE__ == 4 || __INT_LEAST64_TYPE__ == 6)
  171. #define __LEAST64 "l"
  172. #elif (__INT_LEAST64_TYPE__ == 8 || __INT_LEAST64_TYPE__ == 10)
  173. #define __LEAST64 "ll"
  174. #endif
  175. #undef signed
  176. #undef unsigned
  177. #undef char
  178. #undef short
  179. #undef int
  180. #undef long
  181. #pragma pop_macro("signed")
  182. #pragma pop_macro("unsigned")
  183. #pragma pop_macro("char")
  184. #pragma pop_macro("short")
  185. #pragma pop_macro("__int20")
  186. #pragma pop_macro("int")
  187. #pragma pop_macro("long")
  188. #endif /* _SYS__INTSUP_H */