1 /* Test integer width macros in <stdint.h>.
2 Copyright (C) 2016-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
25 #define CHECK_WIDTH(TYPE, MAX, WIDTH) \
28 if ((MAX >> ((TYPE) -1 < 0 ? (WIDTH - 2) : (WIDTH - 1))) != 1) \
30 puts ("bad width of " #TYPE); \
34 puts ("width of " #TYPE " OK"); \
44 # error "missing INT8_WIDTH"
46 CHECK_WIDTH (int8_t, INT8_MAX
, INT8_WIDTH
);
48 # error "missing INT16_WIDTH"
50 CHECK_WIDTH (int16_t, INT16_MAX
, INT16_WIDTH
);
52 # error "missing INT32_WIDTH"
54 CHECK_WIDTH (int32_t, INT32_MAX
, INT32_WIDTH
);
56 # error "missing INT64_WIDTH"
58 CHECK_WIDTH (int64_t, INT64_MAX
, INT64_WIDTH
);
60 # error "missing UINT8_WIDTH"
62 CHECK_WIDTH (uint8_t, UINT8_MAX
, UINT8_WIDTH
);
64 # error "missing UINT16_WIDTH"
66 CHECK_WIDTH (uint16_t, UINT16_MAX
, UINT16_WIDTH
);
68 # error "missing UINT32_WIDTH"
70 CHECK_WIDTH (uint32_t, UINT32_MAX
, UINT32_WIDTH
);
72 # error "missing UINT64_WIDTH"
74 CHECK_WIDTH (uint64_t, UINT64_MAX
, UINT64_WIDTH
);
76 #ifndef INT_LEAST8_WIDTH
77 # error "missing INT_LEAST8_WIDTH"
79 CHECK_WIDTH (int_least8_t, INT_LEAST8_MAX
, INT_LEAST8_WIDTH
);
80 #ifndef INT_LEAST16_WIDTH
81 # error "missing INT_LEAST16_WIDTH"
83 CHECK_WIDTH (int_least16_t, INT_LEAST16_MAX
, INT_LEAST16_WIDTH
);
84 #ifndef INT_LEAST32_WIDTH
85 # error "missing INT_LEAST32_WIDTH"
87 CHECK_WIDTH (int_least32_t, INT_LEAST32_MAX
, INT_LEAST32_WIDTH
);
88 #ifndef INT_LEAST64_WIDTH
89 # error "missing INT_LEAST64_WIDTH"
91 CHECK_WIDTH (int_least64_t, INT_LEAST64_MAX
, INT_LEAST64_WIDTH
);
92 #ifndef UINT_LEAST8_WIDTH
93 # error "missing UINT_LEAST8_WIDTH"
95 CHECK_WIDTH (uint_least8_t, UINT_LEAST8_MAX
, UINT_LEAST8_WIDTH
);
96 #ifndef UINT_LEAST16_WIDTH
97 # error "missing UINT_LEAST16_WIDTH"
99 CHECK_WIDTH (uint_least16_t, UINT_LEAST16_MAX
, UINT_LEAST16_WIDTH
);
100 #ifndef UINT_LEAST32_WIDTH
101 # error "missing UINT_LEAST32_WIDTH"
103 CHECK_WIDTH (uint_least32_t, UINT_LEAST32_MAX
, UINT_LEAST32_WIDTH
);
104 #ifndef UINT_LEAST64_WIDTH
105 # error "missing UINT_LEAST64_WIDTH"
107 CHECK_WIDTH (uint_least64_t, UINT_LEAST64_MAX
, UINT_LEAST64_WIDTH
);
109 #ifndef INT_FAST8_WIDTH
110 # error "missing INT_FAST8_WIDTH"
112 CHECK_WIDTH (int_fast8_t, INT_FAST8_MAX
, INT_FAST8_WIDTH
);
113 #ifndef INT_FAST16_WIDTH
114 # error "missing INT_FAST16_WIDTH"
116 CHECK_WIDTH (int_fast16_t, INT_FAST16_MAX
, INT_FAST16_WIDTH
);
117 #ifndef INT_FAST32_WIDTH
118 # error "missing INT_FAST32_WIDTH"
120 CHECK_WIDTH (int_fast32_t, INT_FAST32_MAX
, INT_FAST32_WIDTH
);
121 #ifndef INT_FAST64_WIDTH
122 # error "missing INT_FAST64_WIDTH"
124 CHECK_WIDTH (int_fast64_t, INT_FAST64_MAX
, INT_FAST64_WIDTH
);
125 #ifndef UINT_FAST8_WIDTH
126 # error "missing UINT_FAST8_WIDTH"
128 CHECK_WIDTH (uint_fast8_t, UINT_FAST8_MAX
, UINT_FAST8_WIDTH
);
129 #ifndef UINT_FAST16_WIDTH
130 # error "missing UINT_FAST16_WIDTH"
132 CHECK_WIDTH (uint_fast16_t, UINT_FAST16_MAX
, UINT_FAST16_WIDTH
);
133 #ifndef UINT_FAST32_WIDTH
134 # error "missing UINT_FAST32_WIDTH"
136 CHECK_WIDTH (uint_fast32_t, UINT_FAST32_MAX
, UINT_FAST32_WIDTH
);
137 #ifndef UINT_FAST64_WIDTH
138 # error "missing UINT_FAST64_WIDTH"
140 CHECK_WIDTH (uint_fast64_t, UINT_FAST64_MAX
, UINT_FAST64_WIDTH
);
143 # error "missing INTPTR_WIDTH"
145 CHECK_WIDTH (intptr_t, INTPTR_MAX
, INTPTR_WIDTH
);
146 #ifndef UINTPTR_WIDTH
147 # error "missing UINTPTR_WIDTH"
149 CHECK_WIDTH (uintptr_t, UINTPTR_MAX
, UINTPTR_WIDTH
);
152 # error "missing INTMAX_WIDTH"
154 CHECK_WIDTH (intmax_t, INTMAX_MAX
, INTMAX_WIDTH
);
155 #ifndef UINTMAX_WIDTH
156 # error "missing UINTMAX_WIDTH"
158 CHECK_WIDTH (uintmax_t, UINTMAX_MAX
, UINTMAX_WIDTH
);
160 #ifndef PTRDIFF_WIDTH
161 # error "missing PTRDIFF_WIDTH"
163 CHECK_WIDTH (ptrdiff_t, PTRDIFF_MAX
, PTRDIFF_WIDTH
);
164 #ifndef SIG_ATOMIC_WIDTH
165 # error "missing SIG_ATOMIC_WIDTH"
167 CHECK_WIDTH (sig_atomic_t, SIG_ATOMIC_MAX
, SIG_ATOMIC_WIDTH
);
169 # error "missing SIZE_WIDTH"
171 CHECK_WIDTH (size_t, SIZE_MAX
, SIZE_WIDTH
);
173 # error "missing WCHAR_WIDTH"
175 CHECK_WIDTH (wchar_t, WCHAR_MAX
, WCHAR_WIDTH
);
177 # error "missing WINT_WIDTH"
179 CHECK_WIDTH (wint_t, WINT_MAX
, WINT_WIDTH
);
184 #define TEST_FUNCTION do_test ()
185 #include "../test-skeleton.c"