1 /* Test of <stdint.h> substitute.
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 /* Written by Bruno Haible <bruno@clisp.org>, 2006. */
25 /* Whether to enable pedantic checks. */
28 #define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
34 #if __GNUC__ >= 2 && DO_PEDANTIC
35 # define verify_same_types(expr1,expr2) \
36 extern void _verify_func(__LINE__) (__typeof__ (expr1) *); \
37 extern void _verify_func(__LINE__) (__typeof__ (expr2) *);
38 # define _verify_func(line) _verify_func2(line)
39 # define _verify_func2(line) verify_func_ ## line
41 # define verify_same_types(expr1,expr2) extern void verify_func (int)
44 /* 7.18.1.1. Exact-width integer types */
45 /* 7.18.2.1. Limits of exact-width integer types */
47 int8_t a1[3] = { INT8_C (17), INT8_MIN, INT8_MAX };
48 verify (TYPE_MINIMUM (int8_t) == INT8_MIN);
49 verify (TYPE_MAXIMUM (int8_t) == INT8_MAX);
50 verify_same_types (INT8_MIN, (int8_t) 0 + 0);
51 verify_same_types (INT8_MAX, (int8_t) 0 + 0);
53 int16_t a2[3] = { INT16_C (17), INT16_MIN, INT16_MAX };
54 verify (TYPE_MINIMUM (int16_t) == INT16_MIN);
55 verify (TYPE_MAXIMUM (int16_t) == INT16_MAX);
56 verify_same_types (INT16_MIN, (int16_t) 0 + 0);
57 verify_same_types (INT16_MAX, (int16_t) 0 + 0);
59 int32_t a3[3] = { INT32_C (17), INT32_MIN, INT32_MAX };
60 verify (TYPE_MINIMUM (int32_t) == INT32_MIN);
61 verify (TYPE_MAXIMUM (int32_t) == INT32_MAX);
62 verify_same_types (INT32_MIN, (int32_t) 0 + 0);
63 verify_same_types (INT32_MAX, (int32_t) 0 + 0);
66 int64_t a4[3] = { INT64_C (17), INT64_MIN, INT64_MAX };
67 verify (TYPE_MINIMUM (int64_t) == INT64_MIN);
68 verify (TYPE_MAXIMUM (int64_t) == INT64_MAX);
69 verify_same_types (INT64_MIN, (int64_t) 0 + 0);
70 verify_same_types (INT64_MAX, (int64_t) 0 + 0);
73 uint8_t b1[2] = { UINT8_C (17), UINT8_MAX };
74 verify (TYPE_MAXIMUM (uint8_t) == UINT8_MAX);
75 verify_same_types (UINT8_MAX, (uint8_t) 0 + 0);
77 uint16_t b2[2] = { UINT16_C (17), UINT16_MAX };
78 verify (TYPE_MAXIMUM (uint16_t) == UINT16_MAX);
79 verify_same_types (UINT16_MAX, (uint16_t) 0 + 0);
81 uint32_t b3[2] = { UINT32_C (17), UINT32_MAX };
82 verify (TYPE_MAXIMUM (uint32_t) == UINT32_MAX);
83 verify_same_types (UINT32_MAX, (uint32_t) 0 + 0);
86 uint64_t b4[2] = { UINT64_C (17), UINT64_MAX };
87 verify (TYPE_MAXIMUM (uint64_t) == UINT64_MAX);
88 verify_same_types (UINT64_MAX, (uint64_t) 0 + 0);
91 #if INT8_MIN && INT8_MAX && INT16_MIN && INT16_MAX && INT32_MIN && INT32_MAX
97 #if UINT8_MAX && UINT16_MAX && UINT32_MAX
103 /* 7.18.1.2. Minimum-width integer types */
104 /* 7.18.2.2. Limits of minimum-width integer types */
106 int_least8_t c1[3] = { 17, INT_LEAST8_MIN, INT_LEAST8_MAX };
107 verify (TYPE_MINIMUM (int_least8_t) == INT_LEAST8_MIN);
108 verify (TYPE_MAXIMUM (int_least8_t) == INT_LEAST8_MAX);
109 verify_same_types (INT_LEAST8_MIN, (int_least8_t) 0 + 0);
110 verify_same_types (INT_LEAST8_MAX, (int_least8_t) 0 + 0);
112 int_least16_t c2[3] = { 17, INT_LEAST16_MIN, INT_LEAST16_MAX };
113 verify (TYPE_MINIMUM (int_least16_t) == INT_LEAST16_MIN);
114 verify (TYPE_MAXIMUM (int_least16_t) == INT_LEAST16_MAX);
115 verify_same_types (INT_LEAST16_MIN, (int_least16_t) 0 + 0);
116 verify_same_types (INT_LEAST16_MAX, (int_least16_t) 0 + 0);
118 int_least32_t c3[3] = { 17, INT_LEAST32_MIN, INT_LEAST32_MAX };
119 verify (TYPE_MINIMUM (int_least32_t) == INT_LEAST32_MIN);
120 verify (TYPE_MAXIMUM (int_least32_t) == INT_LEAST32_MAX);
121 verify_same_types (INT_LEAST32_MIN, (int_least32_t) 0 + 0);
122 verify_same_types (INT_LEAST32_MAX, (int_least32_t) 0 + 0);
124 #ifdef INT_LEAST64_MAX
125 int_least64_t c4[3] = { 17, INT_LEAST64_MIN, INT_LEAST64_MAX };
126 verify (TYPE_MINIMUM (int_least64_t) == INT_LEAST64_MIN);
127 verify (TYPE_MAXIMUM (int_least64_t) == INT_LEAST64_MAX);
128 verify_same_types (INT_LEAST64_MIN, (int_least64_t) 0 + 0);
129 verify_same_types (INT_LEAST64_MAX, (int_least64_t) 0 + 0);
132 uint_least8_t d1[2] = { 17, UINT_LEAST8_MAX };
133 verify (TYPE_MAXIMUM (uint_least8_t) == UINT_LEAST8_MAX);
134 verify_same_types (UINT_LEAST8_MAX, (uint_least8_t) 0 + 0);
136 uint_least16_t d2[2] = { 17, UINT_LEAST16_MAX };
137 verify (TYPE_MAXIMUM (uint_least16_t) == UINT_LEAST16_MAX);
138 verify_same_types (UINT_LEAST16_MAX, (uint_least16_t) 0 + 0);
140 uint_least32_t d3[2] = { 17, UINT_LEAST32_MAX };
141 verify (TYPE_MAXIMUM (uint_least32_t) == UINT_LEAST32_MAX);
142 verify_same_types (UINT_LEAST32_MAX, (uint_least32_t) 0 + 0);
144 #ifdef UINT_LEAST64_MAX
145 uint_least64_t d4[2] = { 17, UINT_LEAST64_MAX };
146 verify (TYPE_MAXIMUM (uint_least64_t) == UINT_LEAST64_MAX);
147 verify_same_types (UINT_LEAST64_MAX, (uint_least64_t) 0 + 0);
150 #if INT_LEAST8_MIN && INT_LEAST8_MAX && INT_LEAST16_MIN && INT_LEAST16_MAX && INT_LEAST32_MIN && INT_LEAST32_MAX
156 #if UINT_LEAST8_MAX && UINT_LEAST16_MAX && UINT_LEAST32_MAX
162 /* 7.18.1.3. Fastest minimum-width integer types */
163 /* 7.18.2.3. Limits of fastest minimum-width integer types */
165 int_fast8_t e1[3] = { 17, INT_FAST8_MIN, INT_FAST8_MAX };
166 verify (TYPE_MINIMUM (int_fast8_t) == INT_FAST8_MIN);
167 verify (TYPE_MAXIMUM (int_fast8_t) == INT_FAST8_MAX);
168 verify_same_types (INT_FAST8_MIN, (int_fast8_t) 0 + 0);
169 verify_same_types (INT_FAST8_MAX, (int_fast8_t) 0 + 0);
171 int_fast16_t e2[3] = { 17, INT_FAST16_MIN, INT_FAST16_MAX };
172 verify (TYPE_MINIMUM (int_fast16_t) == INT_FAST16_MIN);
173 verify (TYPE_MAXIMUM (int_fast16_t) == INT_FAST16_MAX);
174 verify_same_types (INT_FAST16_MIN, (int_fast16_t) 0 + 0);
175 verify_same_types (INT_FAST16_MAX, (int_fast16_t) 0 + 0);
177 int_fast32_t e3[3] = { 17, INT_FAST32_MIN, INT_FAST32_MAX };
178 verify (TYPE_MINIMUM (int_fast32_t) == INT_FAST32_MIN);
179 verify (TYPE_MAXIMUM (int_fast32_t) == INT_FAST32_MAX);
180 verify_same_types (INT_FAST32_MIN, (int_fast32_t) 0 + 0);
181 verify_same_types (INT_FAST32_MAX, (int_fast32_t) 0 + 0);
183 #ifdef INT_FAST64_MAX
184 int_fast64_t e4[3] = { 17, INT_FAST64_MIN, INT_FAST64_MAX };
185 verify (TYPE_MINIMUM (int_fast64_t) == INT_FAST64_MIN);
186 verify (TYPE_MAXIMUM (int_fast64_t) == INT_FAST64_MAX);
187 verify_same_types (INT_FAST64_MIN, (int_fast64_t) 0 + 0);
188 verify_same_types (INT_FAST64_MAX, (int_fast64_t) 0 + 0);
191 uint_fast8_t f1[2] = { 17, UINT_FAST8_MAX };
192 verify (TYPE_MAXIMUM (uint_fast8_t) == UINT_FAST8_MAX);
193 verify_same_types (UINT_FAST8_MAX, (uint_fast8_t) 0 + 0);
195 uint_fast16_t f2[2] = { 17, UINT_FAST16_MAX };
196 verify (TYPE_MAXIMUM (uint_fast16_t) == UINT_FAST16_MAX);
197 verify_same_types (UINT_FAST16_MAX, (uint_fast16_t) 0 + 0);
199 uint_fast32_t f3[2] = { 17, UINT_FAST32_MAX };
200 verify (TYPE_MAXIMUM (uint_fast32_t) == UINT_FAST32_MAX);
201 verify_same_types (UINT_FAST32_MAX, (uint_fast32_t) 0 + 0);
203 #ifdef UINT_FAST64_MAX
204 uint_fast64_t f4[2] = { 17, UINT_FAST64_MAX };
205 verify (TYPE_MAXIMUM (uint_fast64_t) == UINT_FAST64_MAX);
206 verify_same_types (UINT_FAST64_MAX, (uint_fast64_t) 0 + 0);
209 #if INT_FAST8_MIN && INT_FAST8_MAX && INT_FAST16_MIN && INT_FAST16_MAX && INT_FAST32_MIN && INT_FAST32_MAX
215 #if UINT_FAST8_MAX && UINT_FAST16_MAX && UINT_FAST32_MAX
221 /* 7.18.1.4. Integer types capable of holding object pointers */
222 /* 7.18.2.4. Limits of integer types capable of holding object pointers */
224 intptr_t g[3] = { 17, INTPTR_MIN, INTPTR_MAX };
225 verify (TYPE_MINIMUM (intptr_t) == INTPTR_MIN);
226 verify (TYPE_MAXIMUM (intptr_t) == INTPTR_MAX);
227 verify_same_types (INTPTR_MIN, (intptr_t) 0 + 0);
228 verify_same_types (INTPTR_MAX, (intptr_t) 0 + 0);
230 uintptr_t h[2] = { 17, UINTPTR_MAX };
231 verify (TYPE_MAXIMUM (uintptr_t) == UINTPTR_MAX);
232 verify_same_types (UINTPTR_MAX, (uintptr_t) 0 + 0);
234 #if INTPTR_MIN && INTPTR_MAX && UINTPTR_MAX
240 /* 7.18.1.5. Greatest-width integer types */
241 /* 7.18.2.5. Limits of greatest-width integer types */
243 intmax_t i[3] = { INTMAX_C (17), INTMAX_MIN, INTMAX_MAX };
244 verify (TYPE_MINIMUM (intmax_t) == INTMAX_MIN);
245 verify (TYPE_MAXIMUM (intmax_t) == INTMAX_MAX);
246 verify_same_types (INTMAX_MIN, (intmax_t) 0 + 0);
247 verify_same_types (INTMAX_MAX, (intmax_t) 0 + 0);
249 uintmax_t j[2] = { UINTMAX_C (17), UINTMAX_MAX };
250 verify (TYPE_MAXIMUM (uintmax_t) == UINTMAX_MAX);
251 verify_same_types (UINTMAX_MAX, (uintmax_t) 0 + 0);
253 #if INTMAX_MIN && INTMAX_MAX && UINTMAX_MAX
259 /* 7.18.3. Limits of other integer types */
263 verify (TYPE_MINIMUM (ptrdiff_t) == PTRDIFF_MIN);
264 verify (TYPE_MAXIMUM (ptrdiff_t) == PTRDIFF_MAX);
265 verify_same_types (PTRDIFF_MIN, (ptrdiff_t) 0 + 0);
266 verify_same_types (PTRDIFF_MAX, (ptrdiff_t) 0 + 0);
268 #if PTRDIFF_MIN && PTRDIFF_MAX
276 verify (TYPE_MINIMUM (sig_atomic_t) == SIG_ATOMIC_MIN);
277 verify (TYPE_MAXIMUM (sig_atomic_t) == SIG_ATOMIC_MAX);
278 verify_same_types (SIG_ATOMIC_MIN, (sig_atomic_t) 0 + 0);
279 verify_same_types (SIG_ATOMIC_MAX, (sig_atomic_t) 0 + 0);
281 #if SIG_ATOMIC_MIN != 17 && SIG_ATOMIC_MAX
287 verify (TYPE_MAXIMUM (size_t) == SIZE_MAX);
288 verify_same_types (SIZE_MAX, (size_t) 0 + 0);
297 verify (TYPE_MINIMUM (wchar_t) == WCHAR_MIN);
298 verify (TYPE_MAXIMUM (wchar_t) == WCHAR_MAX);
299 verify_same_types (WCHAR_MIN, (wchar_t) 0 + 0);
300 verify_same_types (WCHAR_MAX, (wchar_t) 0 + 0);
302 # if WCHAR_MIN != 17 && WCHAR_MAX
316 verify (TYPE_MINIMUM (wint_t) == WINT_MIN);
317 verify (TYPE_MAXIMUM (wint_t) == WINT_MAX);
318 verify_same_types (WINT_MIN, (wint_t) 0 + 0);
319 verify_same_types (WINT_MAX, (wint_t) 0 + 0);
321 # if WINT_MIN != 17 && WINT_MAX
328 /* 7.18.4. Macros for integer constants */
330 verify (INT8_C (17) == 17);
331 verify_same_types (INT8_C (17), (int_least8_t)0 + 0);
332 verify (UINT8_C (17) == 17);
333 verify_same_types (UINT8_C (17), (uint_least8_t)0 + 0);
335 verify (INT16_C (17) == 17);
336 verify_same_types (INT16_C (17), (int_least16_t)0 + 0);
337 verify (UINT16_C (17) == 17);
338 verify_same_types (UINT16_C (17), (uint_least16_t)0 + 0);
340 verify (INT32_C (17) == 17);
341 verify_same_types (INT32_C (17), (int_least32_t)0 + 0);
342 verify (UINT32_C (17) == 17);
343 verify_same_types (UINT32_C (17), (uint_least32_t)0 + 0);
346 verify (INT64_C (17) == 17);
347 verify_same_types (INT64_C (17), (int_least64_t)0 + 0);
350 verify (UINT64_C (17) == 17);
351 verify_same_types (UINT64_C (17), (uint_least64_t)0 + 0);
354 verify (INTMAX_C (17) == 17);
355 verify_same_types (INTMAX_C (17), (intmax_t)0 + 0);
356 verify (UINTMAX_C (17) == 17);
357 verify_same_types (UINTMAX_C (17), (uintmax_t)0 + 0);