_intsup.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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("__int20__")
  37. #pragma push_macro("int")
  38. #pragma push_macro("long")
  39. #undef signed
  40. #undef unsigned
  41. #undef char
  42. #undef short
  43. #undef int
  44. #undef __int20
  45. #undef __int20__
  46. #undef long
  47. #define signed +0
  48. #define unsigned +0
  49. #define char +0
  50. #define short +1
  51. #define __int20 +2
  52. #define __int20__ +2
  53. #define int +2
  54. #define long +4
  55. #if (__INTPTR_TYPE__ == 8 || __INTPTR_TYPE__ == 10)
  56. #define _INTPTR_EQ_LONGLONG
  57. #elif (__INTPTR_TYPE__ == 4 || __INTPTR_TYPE__ == 6)
  58. #define _INTPTR_EQ_LONG
  59. /* Note - the tests for _INTPTR_EQ_INT and _INTPTR_EQ_SHORT are currently
  60. redundant as the values are not used. But one day they may be needed
  61. and so the tests remain. */
  62. #elif __INTPTR_TYPE__ == 2
  63. #define _INTPTR_EQ_INT
  64. #elif (__INTPTR_TYPE__ == 1 || __INTPTR_TYPE__ == 3)
  65. #define _INTPTR_EQ_SHORT
  66. #else
  67. #error "Unable to determine type definition of intptr_t"
  68. #endif
  69. #if (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6)
  70. #define _INT32_EQ_LONG
  71. #elif __INT32_TYPE__ == 2
  72. /* Nothing to define because int32_t is safe to print as an int. */
  73. #else
  74. #error "Unable to determine type definition of int32_t"
  75. #endif
  76. #if (__INT8_TYPE__ == 0)
  77. #define __INT8 "hh"
  78. #elif (__INT8_TYPE__ == 1 || __INT8_TYPE__ == 3)
  79. #define __INT8 "h"
  80. #elif (__INT8_TYPE__ == 2)
  81. #define __INT8
  82. #elif (__INT8_TYPE__ == 4 || __INT8_TYPE__ == 6)
  83. #define __INT8 "l"
  84. #elif (__INT8_TYPE__ == 8 || __INT8_TYPE__ == 10)
  85. #define __INT8 "ll"
  86. #endif
  87. #if (__INT16_TYPE__ == 1 || __INT16_TYPE__ == 3)
  88. #define __INT16 "h"
  89. #elif (__INT16_TYPE__ == 2)
  90. #define __INT16
  91. #elif (__INT16_TYPE__ == 4 || __INT16_TYPE__ == 6)
  92. #define __INT16 "l"
  93. #elif (__INT16_TYPE__ == 8 || __INT16_TYPE__ == 10)
  94. #define __INT16 "ll"
  95. #endif
  96. #if (__INT32_TYPE__ == 2)
  97. #define __INT32
  98. #elif (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6)
  99. #define __INT32 "l"
  100. #elif (__INT32_TYPE__ == 8 || __INT32_TYPE__ == 10)
  101. #define __INT32 "ll"
  102. #endif
  103. #if (__INT64_TYPE__ == 2)
  104. #define __INT64
  105. #elif (__INT64_TYPE__ == 4 || __INT64_TYPE__ == 6)
  106. #define __INT64 "l"
  107. #elif (__INT64_TYPE__ == 8 || __INT64_TYPE__ == 10)
  108. #define __INT64 "ll"
  109. #endif
  110. #if (__INT_FAST8_TYPE__ == 0)
  111. #define __FAST8 "hh"
  112. #elif (__INT_FAST8_TYPE__ == 1 || __INT_FAST8_TYPE__ == 3)
  113. #define __FAST8 "h"
  114. #elif (__INT_FAST8_TYPE__ == 2)
  115. #define __FAST8
  116. #elif (__INT_FAST8_TYPE__ == 4 || __INT_FAST8_TYPE__ == 6)
  117. #define __FAST8 "l"
  118. #elif (__INT_FAST8_TYPE__ == 8 || __INT_FAST8_TYPE__ == 10)
  119. #define __FAST8 "ll"
  120. #endif
  121. #if (__INT_FAST16_TYPE__ == 1 || __INT_FAST16_TYPE__ == 3)
  122. #define __FAST16 "h"
  123. #elif (__INT_FAST16_TYPE__ == 2)
  124. #define __FAST16
  125. #elif (__INT_FAST16_TYPE__ == 4 || __INT_FAST16_TYPE__ == 6)
  126. #define __FAST16 "l"
  127. #elif (__INT_FAST16_TYPE__ == 8 || __INT_FAST16_TYPE__ == 10)
  128. #define __FAST16 "ll"
  129. #endif
  130. #if (__INT_FAST32_TYPE__ == 2)
  131. #define __FAST32
  132. #elif (__INT_FAST32_TYPE__ == 4 || __INT_FAST32_TYPE__ == 6)
  133. #define __FAST32 "l"
  134. #elif (__INT_FAST32_TYPE__ == 8 || __INT_FAST32_TYPE__ == 10)
  135. #define __FAST32 "ll"
  136. #endif
  137. #if (__INT_FAST64_TYPE__ == 2)
  138. #define __FAST64
  139. #elif (__INT_FAST64_TYPE__ == 4 || __INT_FAST64_TYPE__ == 6)
  140. #define __FAST64 "l"
  141. #elif (__INT_FAST64_TYPE__ == 8 || __INT_FAST64_TYPE__ == 10)
  142. #define __FAST64 "ll"
  143. #endif
  144. #if (__INT_LEAST8_TYPE__ == 0)
  145. #define __LEAST8 "hh"
  146. #elif (__INT_LEAST8_TYPE__ == 1 || __INT_LEAST8_TYPE__ == 3)
  147. #define __LEAST8 "h"
  148. #elif (__INT_LEAST8_TYPE__ == 2)
  149. #define __LEAST8
  150. #elif (__INT_LEAST8_TYPE__ == 4 || __INT_LEAST8_TYPE__ == 6)
  151. #define __LEAST8 "l"
  152. #elif (__INT_LEAST8_TYPE__ == 8 || __INT_LEAST8_TYPE__ == 10)
  153. #define __LEAST8 "ll"
  154. #endif
  155. #if (__INT_LEAST16_TYPE__ == 1 || __INT_LEAST16_TYPE__ == 3)
  156. #define __LEAST16 "h"
  157. #elif (__INT_LEAST16_TYPE__ == 2)
  158. #define __LEAST16
  159. #elif (__INT_LEAST16_TYPE__ == 4 || __INT_LEAST16_TYPE__ == 6)
  160. #define __LEAST16 "l"
  161. #elif (__INT_LEAST16_TYPE__ == 8 || __INT_LEAST16_TYPE__ == 10)
  162. #define __LEAST16 "ll"
  163. #endif
  164. #if (__INT_LEAST32_TYPE__ == 2)
  165. #define __LEAST32
  166. #elif (__INT_LEAST32_TYPE__ == 4 || __INT_LEAST32_TYPE__ == 6)
  167. #define __LEAST32 "l"
  168. #elif (__INT_LEAST32_TYPE__ == 8 || __INT_LEAST32_TYPE__ == 10)
  169. #define __LEAST32 "ll"
  170. #endif
  171. #if (__INT_LEAST64_TYPE__ == 2)
  172. #define __LEAST64
  173. #elif (__INT_LEAST64_TYPE__ == 4 || __INT_LEAST64_TYPE__ == 6)
  174. #define __LEAST64 "l"
  175. #elif (__INT_LEAST64_TYPE__ == 8 || __INT_LEAST64_TYPE__ == 10)
  176. #define __LEAST64 "ll"
  177. #endif
  178. #undef signed
  179. #undef unsigned
  180. #undef char
  181. #undef short
  182. #undef int
  183. #undef long
  184. #pragma pop_macro("signed")
  185. #pragma pop_macro("unsigned")
  186. #pragma pop_macro("char")
  187. #pragma pop_macro("short")
  188. #pragma pop_macro("__int20")
  189. #pragma pop_macro("__int20__")
  190. #pragma pop_macro("int")
  191. #pragma pop_macro("long")
  192. #endif /* _SYS__INTSUP_H */