tst-width-stdint.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* Test integer width macros in <stdint.h>.
  2. Copyright (C) 2016-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <signal.h>
  16. #include <stddef.h>
  17. #include <stdint.h>
  18. #include <stdio.h>
  19. #include <wchar.h>
  20. #define CHECK_WIDTH(TYPE, MAX, WIDTH) \
  21. do \
  22. { \
  23. if ((MAX >> ((TYPE) -1 < 0 ? (WIDTH - 2) : (WIDTH - 1))) != 1) \
  24. { \
  25. puts ("bad width of " #TYPE); \
  26. result = 1; \
  27. } \
  28. else \
  29. puts ("width of " #TYPE " OK"); \
  30. } \
  31. while (0)
  32. static int
  33. do_test (void)
  34. {
  35. int result = 0;
  36. #ifndef INT8_WIDTH
  37. # error "missing INT8_WIDTH"
  38. #endif
  39. CHECK_WIDTH (int8_t, INT8_MAX, INT8_WIDTH);
  40. #ifndef INT16_WIDTH
  41. # error "missing INT16_WIDTH"
  42. #endif
  43. CHECK_WIDTH (int16_t, INT16_MAX, INT16_WIDTH);
  44. #ifndef INT32_WIDTH
  45. # error "missing INT32_WIDTH"
  46. #endif
  47. CHECK_WIDTH (int32_t, INT32_MAX, INT32_WIDTH);
  48. #ifndef INT64_WIDTH
  49. # error "missing INT64_WIDTH"
  50. #endif
  51. CHECK_WIDTH (int64_t, INT64_MAX, INT64_WIDTH);
  52. #ifndef UINT8_WIDTH
  53. # error "missing UINT8_WIDTH"
  54. #endif
  55. CHECK_WIDTH (uint8_t, UINT8_MAX, UINT8_WIDTH);
  56. #ifndef UINT16_WIDTH
  57. # error "missing UINT16_WIDTH"
  58. #endif
  59. CHECK_WIDTH (uint16_t, UINT16_MAX, UINT16_WIDTH);
  60. #ifndef UINT32_WIDTH
  61. # error "missing UINT32_WIDTH"
  62. #endif
  63. CHECK_WIDTH (uint32_t, UINT32_MAX, UINT32_WIDTH);
  64. #ifndef UINT64_WIDTH
  65. # error "missing UINT64_WIDTH"
  66. #endif
  67. CHECK_WIDTH (uint64_t, UINT64_MAX, UINT64_WIDTH);
  68. #ifndef INT_LEAST8_WIDTH
  69. # error "missing INT_LEAST8_WIDTH"
  70. #endif
  71. CHECK_WIDTH (int_least8_t, INT_LEAST8_MAX, INT_LEAST8_WIDTH);
  72. #ifndef INT_LEAST16_WIDTH
  73. # error "missing INT_LEAST16_WIDTH"
  74. #endif
  75. CHECK_WIDTH (int_least16_t, INT_LEAST16_MAX, INT_LEAST16_WIDTH);
  76. #ifndef INT_LEAST32_WIDTH
  77. # error "missing INT_LEAST32_WIDTH"
  78. #endif
  79. CHECK_WIDTH (int_least32_t, INT_LEAST32_MAX, INT_LEAST32_WIDTH);
  80. #ifndef INT_LEAST64_WIDTH
  81. # error "missing INT_LEAST64_WIDTH"
  82. #endif
  83. CHECK_WIDTH (int_least64_t, INT_LEAST64_MAX, INT_LEAST64_WIDTH);
  84. #ifndef UINT_LEAST8_WIDTH
  85. # error "missing UINT_LEAST8_WIDTH"
  86. #endif
  87. CHECK_WIDTH (uint_least8_t, UINT_LEAST8_MAX, UINT_LEAST8_WIDTH);
  88. #ifndef UINT_LEAST16_WIDTH
  89. # error "missing UINT_LEAST16_WIDTH"
  90. #endif
  91. CHECK_WIDTH (uint_least16_t, UINT_LEAST16_MAX, UINT_LEAST16_WIDTH);
  92. #ifndef UINT_LEAST32_WIDTH
  93. # error "missing UINT_LEAST32_WIDTH"
  94. #endif
  95. CHECK_WIDTH (uint_least32_t, UINT_LEAST32_MAX, UINT_LEAST32_WIDTH);
  96. #ifndef UINT_LEAST64_WIDTH
  97. # error "missing UINT_LEAST64_WIDTH"
  98. #endif
  99. CHECK_WIDTH (uint_least64_t, UINT_LEAST64_MAX, UINT_LEAST64_WIDTH);
  100. #ifndef INT_FAST8_WIDTH
  101. # error "missing INT_FAST8_WIDTH"
  102. #endif
  103. CHECK_WIDTH (int_fast8_t, INT_FAST8_MAX, INT_FAST8_WIDTH);
  104. #ifndef INT_FAST16_WIDTH
  105. # error "missing INT_FAST16_WIDTH"
  106. #endif
  107. CHECK_WIDTH (int_fast16_t, INT_FAST16_MAX, INT_FAST16_WIDTH);
  108. #ifndef INT_FAST32_WIDTH
  109. # error "missing INT_FAST32_WIDTH"
  110. #endif
  111. CHECK_WIDTH (int_fast32_t, INT_FAST32_MAX, INT_FAST32_WIDTH);
  112. #ifndef INT_FAST64_WIDTH
  113. # error "missing INT_FAST64_WIDTH"
  114. #endif
  115. CHECK_WIDTH (int_fast64_t, INT_FAST64_MAX, INT_FAST64_WIDTH);
  116. #ifndef UINT_FAST8_WIDTH
  117. # error "missing UINT_FAST8_WIDTH"
  118. #endif
  119. CHECK_WIDTH (uint_fast8_t, UINT_FAST8_MAX, UINT_FAST8_WIDTH);
  120. #ifndef UINT_FAST16_WIDTH
  121. # error "missing UINT_FAST16_WIDTH"
  122. #endif
  123. CHECK_WIDTH (uint_fast16_t, UINT_FAST16_MAX, UINT_FAST16_WIDTH);
  124. #ifndef UINT_FAST32_WIDTH
  125. # error "missing UINT_FAST32_WIDTH"
  126. #endif
  127. CHECK_WIDTH (uint_fast32_t, UINT_FAST32_MAX, UINT_FAST32_WIDTH);
  128. #ifndef UINT_FAST64_WIDTH
  129. # error "missing UINT_FAST64_WIDTH"
  130. #endif
  131. CHECK_WIDTH (uint_fast64_t, UINT_FAST64_MAX, UINT_FAST64_WIDTH);
  132. #ifndef INTPTR_WIDTH
  133. # error "missing INTPTR_WIDTH"
  134. #endif
  135. CHECK_WIDTH (intptr_t, INTPTR_MAX, INTPTR_WIDTH);
  136. #ifndef UINTPTR_WIDTH
  137. # error "missing UINTPTR_WIDTH"
  138. #endif
  139. CHECK_WIDTH (uintptr_t, UINTPTR_MAX, UINTPTR_WIDTH);
  140. #ifndef INTMAX_WIDTH
  141. # error "missing INTMAX_WIDTH"
  142. #endif
  143. CHECK_WIDTH (intmax_t, INTMAX_MAX, INTMAX_WIDTH);
  144. #ifndef UINTMAX_WIDTH
  145. # error "missing UINTMAX_WIDTH"
  146. #endif
  147. CHECK_WIDTH (uintmax_t, UINTMAX_MAX, UINTMAX_WIDTH);
  148. #ifndef PTRDIFF_WIDTH
  149. # error "missing PTRDIFF_WIDTH"
  150. #endif
  151. CHECK_WIDTH (ptrdiff_t, PTRDIFF_MAX, PTRDIFF_WIDTH);
  152. #ifndef SIG_ATOMIC_WIDTH
  153. # error "missing SIG_ATOMIC_WIDTH"
  154. #endif
  155. CHECK_WIDTH (sig_atomic_t, SIG_ATOMIC_MAX, SIG_ATOMIC_WIDTH);
  156. #ifndef SIZE_WIDTH
  157. # error "missing SIZE_WIDTH"
  158. #endif
  159. CHECK_WIDTH (size_t, SIZE_MAX, SIZE_WIDTH);
  160. #ifndef WCHAR_WIDTH
  161. # error "missing WCHAR_WIDTH"
  162. #endif
  163. CHECK_WIDTH (wchar_t, WCHAR_MAX, WCHAR_WIDTH);
  164. #ifndef WINT_WIDTH
  165. # error "missing WINT_WIDTH"
  166. #endif
  167. CHECK_WIDTH (wint_t, WINT_MAX, WINT_WIDTH);
  168. return result;
  169. }
  170. #define TEST_FUNCTION do_test ()
  171. #include "../test-skeleton.c"