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
5 it under the terms of the GNU General Public License as published by
6 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 /* Written by Bruno Haible <bruno@clisp.org>, 2006. */
24 /* Whether to enable pedantic checks. */
27 #define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
33 #if __GNUC__ >= 2 && DO_PEDANTIC
34 # define verify_same_types(expr1,expr2) \
35 extern void _verify_func(__LINE__) (__typeof__ (expr1) *); \
36 extern void _verify_func(__LINE__) (__typeof__ (expr2) *);
37 # define _verify_func(line) _verify_func2(line)
38 # define _verify_func2(line) verify_func_ ## line
40 # define verify_same_types(expr1,expr2) extern void verify_func (int)
43 /* 7.18.1.1. Exact-width integer types */
44 /* 7.18.2.1. Limits of exact-width integer types */
46 int8_t a1[3] = { INT8_C (17), INT8_MIN, INT8_MAX };
47 verify (TYPE_MINIMUM (int8_t) == INT8_MIN);
48 verify (TYPE_MAXIMUM (int8_t) == INT8_MAX);
49 verify_same_types (INT8_MIN, (int8_t) 0 + 0);
50 verify_same_types (INT8_MAX, (int8_t) 0 + 0);
52 int16_t a2[3] = { INT16_C (17), INT16_MIN, INT16_MAX };
53 verify (TYPE_MINIMUM (int16_t) == INT16_MIN);
54 verify (TYPE_MAXIMUM (int16_t) == INT16_MAX);
55 verify_same_types (INT16_MIN, (int16_t) 0 + 0);
56 verify_same_types (INT16_MAX, (int16_t) 0 + 0);
58 int32_t a3[3] = { INT32_C (17), INT32_MIN, INT32_MAX };
59 verify (TYPE_MINIMUM (int32_t) == INT32_MIN);
60 verify (TYPE_MAXIMUM (int32_t) == INT32_MAX);
61 verify_same_types (INT32_MIN, (int32_t) 0 + 0);
62 verify_same_types (INT32_MAX, (int32_t) 0 + 0);
65 int64_t a4[3] = { INT64_C (17), INT64_MIN, INT64_MAX };
66 verify (TYPE_MINIMUM (int64_t) == INT64_MIN);
67 verify (TYPE_MAXIMUM (int64_t) == INT64_MAX);
68 verify_same_types (INT64_MIN, (int64_t) 0 + 0);
69 verify_same_types (INT64_MAX, (int64_t) 0 + 0);
72 uint8_t b1[2] = { UINT8_C (17), UINT8_MAX };
73 verify (TYPE_MAXIMUM (uint8_t) == UINT8_MAX);
74 verify_same_types (UINT8_MAX, (uint8_t) 0 + 0);
76 uint16_t b2[2] = { UINT16_C (17), UINT16_MAX };
77 verify (TYPE_MAXIMUM (uint16_t) == UINT16_MAX);
78 verify_same_types (UINT16_MAX, (uint16_t) 0 + 0);
80 uint32_t b3[2] = { UINT32_C (17), UINT32_MAX };
81 verify (TYPE_MAXIMUM (uint32_t) == UINT32_MAX);
82 verify_same_types (UINT32_MAX, (uint32_t) 0 + 0);
85 uint64_t b4[2] = { UINT64_C (17), UINT64_MAX };
86 verify (TYPE_MAXIMUM (uint64_t) == UINT64_MAX);
87 verify_same_types (UINT64_MAX, (uint64_t) 0 + 0);
90 #if INT8_MIN && INT8_MAX && INT16_MIN && INT16_MAX && INT32_MIN && INT32_MAX
96 #if UINT8_MAX && UINT16_MAX && UINT32_MAX
102 /* 7.18.1.2. Minimum-width integer types */
103 /* 7.18.2.2. Limits of minimum-width integer types */
105 int_least8_t c1[3] = { 17, INT_LEAST8_MIN, INT_LEAST8_MAX };
106 verify (TYPE_MINIMUM (int_least8_t) == INT_LEAST8_MIN);
107 verify (TYPE_MAXIMUM (int_least8_t) == INT_LEAST8_MAX);
108 verify_same_types (INT_LEAST8_MIN, (int_least8_t) 0 + 0);
109 verify_same_types (INT_LEAST8_MAX, (int_least8_t) 0 + 0);
111 int_least16_t c2[3] = { 17, INT_LEAST16_MIN, INT_LEAST16_MAX };
112 verify (TYPE_MINIMUM (int_least16_t) == INT_LEAST16_MIN);
113 verify (TYPE_MAXIMUM (int_least16_t) == INT_LEAST16_MAX);
114 verify_same_types (INT_LEAST16_MIN, (int_least16_t) 0 + 0);
115 verify_same_types (INT_LEAST16_MAX, (int_least16_t) 0 + 0);
117 int_least32_t c3[3] = { 17, INT_LEAST32_MIN, INT_LEAST32_MAX };
118 verify (TYPE_MINIMUM (int_least32_t) == INT_LEAST32_MIN);
119 verify (TYPE_MAXIMUM (int_least32_t) == INT_LEAST32_MAX);
120 verify_same_types (INT_LEAST32_MIN, (int_least32_t) 0 + 0);
121 verify_same_types (INT_LEAST32_MAX, (int_least32_t) 0 + 0);
123 #ifdef INT_LEAST64_MAX
124 int_least64_t c4[3] = { 17, INT_LEAST64_MIN, INT_LEAST64_MAX };
125 verify (TYPE_MINIMUM (int_least64_t) == INT_LEAST64_MIN);
126 verify (TYPE_MAXIMUM (int_least64_t) == INT_LEAST64_MAX);
127 verify_same_types (INT_LEAST64_MIN, (int_least64_t) 0 + 0);
128 verify_same_types (INT_LEAST64_MAX, (int_least64_t) 0 + 0);
131 uint_least8_t d1[2] = { 17, UINT_LEAST8_MAX };
132 verify (TYPE_MAXIMUM (uint_least8_t) == UINT_LEAST8_MAX);
133 verify_same_types (UINT_LEAST8_MAX, (uint_least8_t) 0 + 0);
135 uint_least16_t d2[2] = { 17, UINT_LEAST16_MAX };
136 verify (TYPE_MAXIMUM (uint_least16_t) == UINT_LEAST16_MAX);
137 verify_same_types (UINT_LEAST16_MAX, (uint_least16_t) 0 + 0);
139 uint_least32_t d3[2] = { 17, UINT_LEAST32_MAX };
140 verify (TYPE_MAXIMUM (uint_least32_t) == UINT_LEAST32_MAX);
141 verify_same_types (UINT_LEAST32_MAX, (uint_least32_t) 0 + 0);
143 #ifdef UINT_LEAST64_MAX
144 uint_least64_t d4[2] = { 17, UINT_LEAST64_MAX };
145 verify (TYPE_MAXIMUM (uint_least64_t) == UINT_LEAST64_MAX);
146 verify_same_types (UINT_LEAST64_MAX, (uint_least64_t) 0 + 0);
149 #if INT_LEAST8_MIN && INT_LEAST8_MAX && INT_LEAST16_MIN && INT_LEAST16_MAX && INT_LEAST32_MIN && INT_LEAST32_MAX
155 #if UINT_LEAST8_MAX && UINT_LEAST16_MAX && UINT_LEAST32_MAX
161 /* 7.18.1.3. Fastest minimum-width integer types */
162 /* 7.18.2.3. Limits of fastest minimum-width integer types */
164 int_fast8_t e1[3] = { 17, INT_FAST8_MIN, INT_FAST8_MAX };
165 verify (TYPE_MINIMUM (int_fast8_t) == INT_FAST8_MIN);
166 verify (TYPE_MAXIMUM (int_fast8_t) == INT_FAST8_MAX);
167 verify_same_types (INT_FAST8_MIN, (int_fast8_t) 0 + 0);
168 verify_same_types (INT_FAST8_MAX, (int_fast8_t) 0 + 0);
170 int_fast16_t e2[3] = { 17, INT_FAST16_MIN, INT_FAST16_MAX };
171 verify (TYPE_MINIMUM (int_fast16_t) == INT_FAST16_MIN);
172 verify (TYPE_MAXIMUM (int_fast16_t) == INT_FAST16_MAX);
173 verify_same_types (INT_FAST16_MIN, (int_fast16_t) 0 + 0);
174 verify_same_types (INT_FAST16_MAX, (int_fast16_t) 0 + 0);
176 int_fast32_t e3[3] = { 17, INT_FAST32_MIN, INT_FAST32_MAX };
177 verify (TYPE_MINIMUM (int_fast32_t) == INT_FAST32_MIN);
178 verify (TYPE_MAXIMUM (int_fast32_t) == INT_FAST32_MAX);
179 verify_same_types (INT_FAST32_MIN, (int_fast32_t) 0 + 0);
180 verify_same_types (INT_FAST32_MAX, (int_fast32_t) 0 + 0);
182 #ifdef INT_FAST64_MAX
183 int_fast64_t e4[3] = { 17, INT_FAST64_MIN, INT_FAST64_MAX };
184 verify (TYPE_MINIMUM (int_fast64_t) == INT_FAST64_MIN);
185 verify (TYPE_MAXIMUM (int_fast64_t) == INT_FAST64_MAX);
186 verify_same_types (INT_FAST64_MIN, (int_fast64_t) 0 + 0);
187 verify_same_types (INT_FAST64_MAX, (int_fast64_t) 0 + 0);
190 uint_fast8_t f1[2] = { 17, UINT_FAST8_MAX };
191 verify (TYPE_MAXIMUM (uint_fast8_t) == UINT_FAST8_MAX);
192 verify_same_types (UINT_FAST8_MAX, (uint_fast8_t) 0 + 0);
194 uint_fast16_t f2[2] = { 17, UINT_FAST16_MAX };
195 verify (TYPE_MAXIMUM (uint_fast16_t) == UINT_FAST16_MAX);
196 verify_same_types (UINT_FAST16_MAX, (uint_fast16_t) 0 + 0);
198 uint_fast32_t f3[2] = { 17, UINT_FAST32_MAX };
199 verify (TYPE_MAXIMUM (uint_fast32_t) == UINT_FAST32_MAX);
200 verify_same_types (UINT_FAST32_MAX, (uint_fast32_t) 0 + 0);
202 #ifdef UINT_FAST64_MAX
203 uint_fast64_t f4[2] = { 17, UINT_FAST64_MAX };
204 verify (TYPE_MAXIMUM (uint_fast64_t) == UINT_FAST64_MAX);
205 verify_same_types (UINT_FAST64_MAX, (uint_fast64_t) 0 + 0);
208 #if INT_FAST8_MIN && INT_FAST8_MAX && INT_FAST16_MIN && INT_FAST16_MAX && INT_FAST32_MIN && INT_FAST32_MAX
214 #if UINT_FAST8_MAX && UINT_FAST16_MAX && UINT_FAST32_MAX
220 /* 7.18.1.4. Integer types capable of holding object pointers */
221 /* 7.18.2.4. Limits of integer types capable of holding object pointers */
223 intptr_t g[3] = { 17, INTPTR_MIN, INTPTR_MAX };
224 verify (TYPE_MINIMUM (intptr_t) == INTPTR_MIN);
225 verify (TYPE_MAXIMUM (intptr_t) == INTPTR_MAX);
226 verify_same_types (INTPTR_MIN, (intptr_t) 0 + 0);
227 verify_same_types (INTPTR_MAX, (intptr_t) 0 + 0);
229 uintptr_t h[2] = { 17, UINTPTR_MAX };
230 verify (TYPE_MAXIMUM (uintptr_t) == UINTPTR_MAX);
231 verify_same_types (UINTPTR_MAX, (uintptr_t) 0 + 0);
233 #if INTPTR_MIN && INTPTR_MAX && UINTPTR_MAX
239 /* 7.18.1.5. Greatest-width integer types */
240 /* 7.18.2.5. Limits of greatest-width integer types */
242 intmax_t i[3] = { INTMAX_C (17), INTMAX_MIN, INTMAX_MAX };
243 verify (TYPE_MINIMUM (intmax_t) == INTMAX_MIN);
244 verify (TYPE_MAXIMUM (intmax_t) == INTMAX_MAX);
245 verify_same_types (INTMAX_MIN, (intmax_t) 0 + 0);
246 verify_same_types (INTMAX_MAX, (intmax_t) 0 + 0);
248 uintmax_t j[2] = { UINTMAX_C (17), UINTMAX_MAX };
249 verify (TYPE_MAXIMUM (uintmax_t) == UINTMAX_MAX);
250 verify_same_types (UINTMAX_MAX, (uintmax_t) 0 + 0);
252 #if INTMAX_MIN && INTMAX_MAX && UINTMAX_MAX
258 /* 7.18.3. Limits of other integer types */
262 verify (TYPE_MINIMUM (ptrdiff_t) == PTRDIFF_MIN);
263 verify (TYPE_MAXIMUM (ptrdiff_t) == PTRDIFF_MAX);
264 verify_same_types (PTRDIFF_MIN, (ptrdiff_t) 0 + 0);
265 verify_same_types (PTRDIFF_MAX, (ptrdiff_t) 0 + 0);
267 #if PTRDIFF_MIN && PTRDIFF_MAX
275 verify (TYPE_MINIMUM (sig_atomic_t) == SIG_ATOMIC_MIN);
276 verify (TYPE_MAXIMUM (sig_atomic_t) == SIG_ATOMIC_MAX);
277 verify_same_types (SIG_ATOMIC_MIN, (sig_atomic_t) 0 + 0);
278 verify_same_types (SIG_ATOMIC_MAX, (sig_atomic_t) 0 + 0);
280 #if SIG_ATOMIC_MIN != 17 && SIG_ATOMIC_MAX
286 verify (TYPE_MAXIMUM (size_t) == SIZE_MAX);
287 verify_same_types (SIZE_MAX, (size_t) 0 + 0);
296 verify (TYPE_MINIMUM (wchar_t) == WCHAR_MIN);
297 verify (TYPE_MAXIMUM (wchar_t) == WCHAR_MAX);
298 verify_same_types (WCHAR_MIN, (wchar_t) 0 + 0);
299 verify_same_types (WCHAR_MAX, (wchar_t) 0 + 0);
301 # if WCHAR_MIN != 17 && WCHAR_MAX
315 verify (TYPE_MINIMUM (wint_t) == WINT_MIN);
316 verify (TYPE_MAXIMUM (wint_t) == WINT_MAX);
317 verify_same_types (WINT_MIN, (wint_t) 0 + 0);
318 verify_same_types (WINT_MAX, (wint_t) 0 + 0);
320 # if WINT_MIN != 17 && WINT_MAX
327 /* 7.18.4. Macros for integer constants */
329 verify (INT8_C (17) == 17);
330 verify_same_types (INT8_C (17), (int_least8_t)0 + 0);
331 verify (UINT8_C (17) == 17);
332 verify_same_types (UINT8_C (17), (uint_least8_t)0 + 0);
334 verify (INT16_C (17) == 17);
335 verify_same_types (INT16_C (17), (int_least16_t)0 + 0);
336 verify (UINT16_C (17) == 17);
337 verify_same_types (UINT16_C (17), (uint_least16_t)0 + 0);
339 verify (INT32_C (17) == 17);
340 verify_same_types (INT32_C (17), (int_least32_t)0 + 0);
341 verify (UINT32_C (17) == 17);
342 verify_same_types (UINT32_C (17), (uint_least32_t)0 + 0);
345 verify (INT64_C (17) == 17);
346 verify_same_types (INT64_C (17), (int_least64_t)0 + 0);
349 verify (UINT64_C (17) == 17);
350 verify_same_types (UINT64_C (17), (uint_least64_t)0 + 0);
353 verify (INTMAX_C (17) == 17);
354 verify_same_types (INTMAX_C (17), (intmax_t)0 + 0);
355 verify (UINTMAX_C (17) == 17);
356 verify_same_types (UINTMAX_C (17), (uintmax_t)0 + 0);