1 | /* Test integer width macros in <stdint.h>. |
2 | Copyright (C) 2016-2022 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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. |
9 | |
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. |
14 | |
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/>. */ |
18 | |
19 | #include <signal.h> |
20 | #include <stddef.h> |
21 | #include <stdint.h> |
22 | #include <stdio.h> |
23 | #include <wchar.h> |
24 | |
25 | #define CHECK_WIDTH(TYPE, MAX, WIDTH) \ |
26 | do \ |
27 | { \ |
28 | if ((MAX >> ((TYPE) -1 < 0 ? (WIDTH - 2) : (WIDTH - 1))) != 1) \ |
29 | { \ |
30 | puts ("bad width of " #TYPE); \ |
31 | result = 1; \ |
32 | } \ |
33 | else \ |
34 | puts ("width of " #TYPE " OK"); \ |
35 | } \ |
36 | while (0) |
37 | |
38 | static int |
39 | do_test (void) |
40 | { |
41 | int result = 0; |
42 | |
43 | #ifndef INT8_WIDTH |
44 | # error "missing INT8_WIDTH" |
45 | #endif |
46 | CHECK_WIDTH (int8_t, INT8_MAX, INT8_WIDTH); |
47 | #ifndef INT16_WIDTH |
48 | # error "missing INT16_WIDTH" |
49 | #endif |
50 | CHECK_WIDTH (int16_t, INT16_MAX, INT16_WIDTH); |
51 | #ifndef INT32_WIDTH |
52 | # error "missing INT32_WIDTH" |
53 | #endif |
54 | CHECK_WIDTH (int32_t, INT32_MAX, INT32_WIDTH); |
55 | #ifndef INT64_WIDTH |
56 | # error "missing INT64_WIDTH" |
57 | #endif |
58 | CHECK_WIDTH (int64_t, INT64_MAX, INT64_WIDTH); |
59 | #ifndef UINT8_WIDTH |
60 | # error "missing UINT8_WIDTH" |
61 | #endif |
62 | CHECK_WIDTH (uint8_t, UINT8_MAX, UINT8_WIDTH); |
63 | #ifndef UINT16_WIDTH |
64 | # error "missing UINT16_WIDTH" |
65 | #endif |
66 | CHECK_WIDTH (uint16_t, UINT16_MAX, UINT16_WIDTH); |
67 | #ifndef UINT32_WIDTH |
68 | # error "missing UINT32_WIDTH" |
69 | #endif |
70 | CHECK_WIDTH (uint32_t, UINT32_MAX, UINT32_WIDTH); |
71 | #ifndef UINT64_WIDTH |
72 | # error "missing UINT64_WIDTH" |
73 | #endif |
74 | CHECK_WIDTH (uint64_t, UINT64_MAX, UINT64_WIDTH); |
75 | |
76 | #ifndef INT_LEAST8_WIDTH |
77 | # error "missing INT_LEAST8_WIDTH" |
78 | #endif |
79 | CHECK_WIDTH (int_least8_t, INT_LEAST8_MAX, INT_LEAST8_WIDTH); |
80 | #ifndef INT_LEAST16_WIDTH |
81 | # error "missing INT_LEAST16_WIDTH" |
82 | #endif |
83 | CHECK_WIDTH (int_least16_t, INT_LEAST16_MAX, INT_LEAST16_WIDTH); |
84 | #ifndef INT_LEAST32_WIDTH |
85 | # error "missing INT_LEAST32_WIDTH" |
86 | #endif |
87 | CHECK_WIDTH (int_least32_t, INT_LEAST32_MAX, INT_LEAST32_WIDTH); |
88 | #ifndef INT_LEAST64_WIDTH |
89 | # error "missing INT_LEAST64_WIDTH" |
90 | #endif |
91 | CHECK_WIDTH (int_least64_t, INT_LEAST64_MAX, INT_LEAST64_WIDTH); |
92 | #ifndef UINT_LEAST8_WIDTH |
93 | # error "missing UINT_LEAST8_WIDTH" |
94 | #endif |
95 | CHECK_WIDTH (uint_least8_t, UINT_LEAST8_MAX, UINT_LEAST8_WIDTH); |
96 | #ifndef UINT_LEAST16_WIDTH |
97 | # error "missing UINT_LEAST16_WIDTH" |
98 | #endif |
99 | CHECK_WIDTH (uint_least16_t, UINT_LEAST16_MAX, UINT_LEAST16_WIDTH); |
100 | #ifndef UINT_LEAST32_WIDTH |
101 | # error "missing UINT_LEAST32_WIDTH" |
102 | #endif |
103 | CHECK_WIDTH (uint_least32_t, UINT_LEAST32_MAX, UINT_LEAST32_WIDTH); |
104 | #ifndef UINT_LEAST64_WIDTH |
105 | # error "missing UINT_LEAST64_WIDTH" |
106 | #endif |
107 | CHECK_WIDTH (uint_least64_t, UINT_LEAST64_MAX, UINT_LEAST64_WIDTH); |
108 | |
109 | #ifndef INT_FAST8_WIDTH |
110 | # error "missing INT_FAST8_WIDTH" |
111 | #endif |
112 | CHECK_WIDTH (int_fast8_t, INT_FAST8_MAX, INT_FAST8_WIDTH); |
113 | #ifndef INT_FAST16_WIDTH |
114 | # error "missing INT_FAST16_WIDTH" |
115 | #endif |
116 | CHECK_WIDTH (int_fast16_t, INT_FAST16_MAX, INT_FAST16_WIDTH); |
117 | #ifndef INT_FAST32_WIDTH |
118 | # error "missing INT_FAST32_WIDTH" |
119 | #endif |
120 | CHECK_WIDTH (int_fast32_t, INT_FAST32_MAX, INT_FAST32_WIDTH); |
121 | #ifndef INT_FAST64_WIDTH |
122 | # error "missing INT_FAST64_WIDTH" |
123 | #endif |
124 | CHECK_WIDTH (int_fast64_t, INT_FAST64_MAX, INT_FAST64_WIDTH); |
125 | #ifndef UINT_FAST8_WIDTH |
126 | # error "missing UINT_FAST8_WIDTH" |
127 | #endif |
128 | CHECK_WIDTH (uint_fast8_t, UINT_FAST8_MAX, UINT_FAST8_WIDTH); |
129 | #ifndef UINT_FAST16_WIDTH |
130 | # error "missing UINT_FAST16_WIDTH" |
131 | #endif |
132 | CHECK_WIDTH (uint_fast16_t, UINT_FAST16_MAX, UINT_FAST16_WIDTH); |
133 | #ifndef UINT_FAST32_WIDTH |
134 | # error "missing UINT_FAST32_WIDTH" |
135 | #endif |
136 | CHECK_WIDTH (uint_fast32_t, UINT_FAST32_MAX, UINT_FAST32_WIDTH); |
137 | #ifndef UINT_FAST64_WIDTH |
138 | # error "missing UINT_FAST64_WIDTH" |
139 | #endif |
140 | CHECK_WIDTH (uint_fast64_t, UINT_FAST64_MAX, UINT_FAST64_WIDTH); |
141 | |
142 | #ifndef INTPTR_WIDTH |
143 | # error "missing INTPTR_WIDTH" |
144 | #endif |
145 | CHECK_WIDTH (intptr_t, INTPTR_MAX, INTPTR_WIDTH); |
146 | #ifndef UINTPTR_WIDTH |
147 | # error "missing UINTPTR_WIDTH" |
148 | #endif |
149 | CHECK_WIDTH (uintptr_t, UINTPTR_MAX, UINTPTR_WIDTH); |
150 | |
151 | #ifndef INTMAX_WIDTH |
152 | # error "missing INTMAX_WIDTH" |
153 | #endif |
154 | CHECK_WIDTH (intmax_t, INTMAX_MAX, INTMAX_WIDTH); |
155 | #ifndef UINTMAX_WIDTH |
156 | # error "missing UINTMAX_WIDTH" |
157 | #endif |
158 | CHECK_WIDTH (uintmax_t, UINTMAX_MAX, UINTMAX_WIDTH); |
159 | |
160 | #ifndef PTRDIFF_WIDTH |
161 | # error "missing PTRDIFF_WIDTH" |
162 | #endif |
163 | CHECK_WIDTH (ptrdiff_t, PTRDIFF_MAX, PTRDIFF_WIDTH); |
164 | #ifndef SIG_ATOMIC_WIDTH |
165 | # error "missing SIG_ATOMIC_WIDTH" |
166 | #endif |
167 | CHECK_WIDTH (sig_atomic_t, SIG_ATOMIC_MAX, SIG_ATOMIC_WIDTH); |
168 | #ifndef SIZE_WIDTH |
169 | # error "missing SIZE_WIDTH" |
170 | #endif |
171 | CHECK_WIDTH (size_t, SIZE_MAX, SIZE_WIDTH); |
172 | #ifndef WCHAR_WIDTH |
173 | # error "missing WCHAR_WIDTH" |
174 | #endif |
175 | CHECK_WIDTH (wchar_t, WCHAR_MAX, WCHAR_WIDTH); |
176 | #ifndef WINT_WIDTH |
177 | # error "missing WINT_WIDTH" |
178 | #endif |
179 | CHECK_WIDTH (wint_t, WINT_MAX, WINT_WIDTH); |
180 | |
181 | return result; |
182 | } |
183 | |
184 | #define TEST_FUNCTION do_test () |
185 | #include "../test-skeleton.c" |
186 | |