1 | /* Copyright (C) 1997-2017 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | |
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 | |
9 | The GNU C Library 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 | Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ |
17 | |
18 | /* |
19 | * ISO C99: 7.18 Integer types <stdint.h> |
20 | */ |
21 | |
22 | #ifndef _STDINT_H |
23 | #define _STDINT_H 1 |
24 | |
25 | #define |
26 | #include <bits/libc-header-start.h> |
27 | #include <bits/types.h> |
28 | #include <bits/wchar.h> |
29 | #include <bits/wordsize.h> |
30 | |
31 | /* Exact integral types. */ |
32 | |
33 | /* Signed. */ |
34 | |
35 | /* There is some amount of overlap with <sys/types.h> as known by inet code */ |
36 | #ifndef __int8_t_defined |
37 | # define __int8_t_defined |
38 | typedef signed char int8_t; |
39 | typedef short int int16_t; |
40 | typedef int int32_t; |
41 | # if __WORDSIZE == 64 |
42 | typedef long int int64_t; |
43 | # else |
44 | __extension__ |
45 | typedef long long int int64_t; |
46 | # endif |
47 | #endif |
48 | |
49 | /* Unsigned. */ |
50 | typedef unsigned char uint8_t; |
51 | typedef unsigned short int uint16_t; |
52 | #ifndef __uint32_t_defined |
53 | typedef unsigned int uint32_t; |
54 | # define __uint32_t_defined |
55 | #endif |
56 | #if __WORDSIZE == 64 |
57 | typedef unsigned long int uint64_t; |
58 | #else |
59 | __extension__ |
60 | typedef unsigned long long int uint64_t; |
61 | #endif |
62 | |
63 | |
64 | /* Small types. */ |
65 | |
66 | /* Signed. */ |
67 | typedef signed char int_least8_t; |
68 | typedef short int int_least16_t; |
69 | typedef int int_least32_t; |
70 | #if __WORDSIZE == 64 |
71 | typedef long int int_least64_t; |
72 | #else |
73 | __extension__ |
74 | typedef long long int int_least64_t; |
75 | #endif |
76 | |
77 | /* Unsigned. */ |
78 | typedef unsigned char uint_least8_t; |
79 | typedef unsigned short int uint_least16_t; |
80 | typedef unsigned int uint_least32_t; |
81 | #if __WORDSIZE == 64 |
82 | typedef unsigned long int uint_least64_t; |
83 | #else |
84 | __extension__ |
85 | typedef unsigned long long int uint_least64_t; |
86 | #endif |
87 | |
88 | |
89 | /* Fast types. */ |
90 | |
91 | /* Signed. */ |
92 | typedef signed char int_fast8_t; |
93 | #if __WORDSIZE == 64 |
94 | typedef long int int_fast16_t; |
95 | typedef long int int_fast32_t; |
96 | typedef long int int_fast64_t; |
97 | #else |
98 | typedef int int_fast16_t; |
99 | typedef int int_fast32_t; |
100 | __extension__ |
101 | typedef long long int int_fast64_t; |
102 | #endif |
103 | |
104 | /* Unsigned. */ |
105 | typedef unsigned char uint_fast8_t; |
106 | #if __WORDSIZE == 64 |
107 | typedef unsigned long int uint_fast16_t; |
108 | typedef unsigned long int uint_fast32_t; |
109 | typedef unsigned long int uint_fast64_t; |
110 | #else |
111 | typedef unsigned int uint_fast16_t; |
112 | typedef unsigned int uint_fast32_t; |
113 | __extension__ |
114 | typedef unsigned long long int uint_fast64_t; |
115 | #endif |
116 | |
117 | |
118 | /* Types for `void *' pointers. */ |
119 | #if __WORDSIZE == 64 |
120 | # ifndef __intptr_t_defined |
121 | typedef long int intptr_t; |
122 | # define __intptr_t_defined |
123 | # endif |
124 | typedef unsigned long int uintptr_t; |
125 | #else |
126 | # ifndef __intptr_t_defined |
127 | typedef int intptr_t; |
128 | # define __intptr_t_defined |
129 | # endif |
130 | typedef unsigned int uintptr_t; |
131 | #endif |
132 | |
133 | |
134 | /* Largest integral types. */ |
135 | typedef __intmax_t intmax_t; |
136 | typedef __uintmax_t uintmax_t; |
137 | |
138 | |
139 | # if __WORDSIZE == 64 |
140 | # define __INT64_C(c) c ## L |
141 | # define __UINT64_C(c) c ## UL |
142 | # else |
143 | # define __INT64_C(c) c ## LL |
144 | # define __UINT64_C(c) c ## ULL |
145 | # endif |
146 | |
147 | /* Limits of integral types. */ |
148 | |
149 | /* Minimum of signed integral types. */ |
150 | # define INT8_MIN (-128) |
151 | # define INT16_MIN (-32767-1) |
152 | # define INT32_MIN (-2147483647-1) |
153 | # define INT64_MIN (-__INT64_C(9223372036854775807)-1) |
154 | /* Maximum of signed integral types. */ |
155 | # define INT8_MAX (127) |
156 | # define INT16_MAX (32767) |
157 | # define INT32_MAX (2147483647) |
158 | # define INT64_MAX (__INT64_C(9223372036854775807)) |
159 | |
160 | /* Maximum of unsigned integral types. */ |
161 | # define UINT8_MAX (255) |
162 | # define UINT16_MAX (65535) |
163 | # define UINT32_MAX (4294967295U) |
164 | # define UINT64_MAX (__UINT64_C(18446744073709551615)) |
165 | |
166 | |
167 | /* Minimum of signed integral types having a minimum size. */ |
168 | # define INT_LEAST8_MIN (-128) |
169 | # define INT_LEAST16_MIN (-32767-1) |
170 | # define INT_LEAST32_MIN (-2147483647-1) |
171 | # define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1) |
172 | /* Maximum of signed integral types having a minimum size. */ |
173 | # define INT_LEAST8_MAX (127) |
174 | # define INT_LEAST16_MAX (32767) |
175 | # define INT_LEAST32_MAX (2147483647) |
176 | # define INT_LEAST64_MAX (__INT64_C(9223372036854775807)) |
177 | |
178 | /* Maximum of unsigned integral types having a minimum size. */ |
179 | # define UINT_LEAST8_MAX (255) |
180 | # define UINT_LEAST16_MAX (65535) |
181 | # define UINT_LEAST32_MAX (4294967295U) |
182 | # define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615)) |
183 | |
184 | |
185 | /* Minimum of fast signed integral types having a minimum size. */ |
186 | # define INT_FAST8_MIN (-128) |
187 | # if __WORDSIZE == 64 |
188 | # define INT_FAST16_MIN (-9223372036854775807L-1) |
189 | # define INT_FAST32_MIN (-9223372036854775807L-1) |
190 | # else |
191 | # define INT_FAST16_MIN (-2147483647-1) |
192 | # define INT_FAST32_MIN (-2147483647-1) |
193 | # endif |
194 | # define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1) |
195 | /* Maximum of fast signed integral types having a minimum size. */ |
196 | # define INT_FAST8_MAX (127) |
197 | # if __WORDSIZE == 64 |
198 | # define INT_FAST16_MAX (9223372036854775807L) |
199 | # define INT_FAST32_MAX (9223372036854775807L) |
200 | # else |
201 | # define INT_FAST16_MAX (2147483647) |
202 | # define INT_FAST32_MAX (2147483647) |
203 | # endif |
204 | # define INT_FAST64_MAX (__INT64_C(9223372036854775807)) |
205 | |
206 | /* Maximum of fast unsigned integral types having a minimum size. */ |
207 | # define UINT_FAST8_MAX (255) |
208 | # if __WORDSIZE == 64 |
209 | # define UINT_FAST16_MAX (18446744073709551615UL) |
210 | # define UINT_FAST32_MAX (18446744073709551615UL) |
211 | # else |
212 | # define UINT_FAST16_MAX (4294967295U) |
213 | # define UINT_FAST32_MAX (4294967295U) |
214 | # endif |
215 | # define UINT_FAST64_MAX (__UINT64_C(18446744073709551615)) |
216 | |
217 | |
218 | /* Values to test for integral types holding `void *' pointer. */ |
219 | # if __WORDSIZE == 64 |
220 | # define INTPTR_MIN (-9223372036854775807L-1) |
221 | # define INTPTR_MAX (9223372036854775807L) |
222 | # define UINTPTR_MAX (18446744073709551615UL) |
223 | # else |
224 | # define INTPTR_MIN (-2147483647-1) |
225 | # define INTPTR_MAX (2147483647) |
226 | # define UINTPTR_MAX (4294967295U) |
227 | # endif |
228 | |
229 | |
230 | /* Minimum for largest signed integral type. */ |
231 | # define INTMAX_MIN (-__INT64_C(9223372036854775807)-1) |
232 | /* Maximum for largest signed integral type. */ |
233 | # define INTMAX_MAX (__INT64_C(9223372036854775807)) |
234 | |
235 | /* Maximum for largest unsigned integral type. */ |
236 | # define UINTMAX_MAX (__UINT64_C(18446744073709551615)) |
237 | |
238 | |
239 | /* Limits of other integer types. */ |
240 | |
241 | /* Limits of `ptrdiff_t' type. */ |
242 | # if __WORDSIZE == 64 |
243 | # define PTRDIFF_MIN (-9223372036854775807L-1) |
244 | # define PTRDIFF_MAX (9223372036854775807L) |
245 | # else |
246 | # if __WORDSIZE32_PTRDIFF_LONG |
247 | # define PTRDIFF_MIN (-2147483647L-1) |
248 | # define PTRDIFF_MAX (2147483647L) |
249 | # else |
250 | # define PTRDIFF_MIN (-2147483647-1) |
251 | # define PTRDIFF_MAX (2147483647) |
252 | # endif |
253 | # endif |
254 | |
255 | /* Limits of `sig_atomic_t'. */ |
256 | # define SIG_ATOMIC_MIN (-2147483647-1) |
257 | # define SIG_ATOMIC_MAX (2147483647) |
258 | |
259 | /* Limit of `size_t' type. */ |
260 | # if __WORDSIZE == 64 |
261 | # define SIZE_MAX (18446744073709551615UL) |
262 | # else |
263 | # if __WORDSIZE32_SIZE_ULONG |
264 | # define SIZE_MAX (4294967295UL) |
265 | # else |
266 | # define SIZE_MAX (4294967295U) |
267 | # endif |
268 | # endif |
269 | |
270 | /* Limits of `wchar_t'. */ |
271 | # ifndef WCHAR_MIN |
272 | /* These constants might also be defined in <wchar.h>. */ |
273 | # define WCHAR_MIN __WCHAR_MIN |
274 | # define WCHAR_MAX __WCHAR_MAX |
275 | # endif |
276 | |
277 | /* Limits of `wint_t'. */ |
278 | # define WINT_MIN (0u) |
279 | # define WINT_MAX (4294967295u) |
280 | |
281 | /* Signed. */ |
282 | # define INT8_C(c) c |
283 | # define INT16_C(c) c |
284 | # define INT32_C(c) c |
285 | # if __WORDSIZE == 64 |
286 | # define INT64_C(c) c ## L |
287 | # else |
288 | # define INT64_C(c) c ## LL |
289 | # endif |
290 | |
291 | /* Unsigned. */ |
292 | # define UINT8_C(c) c |
293 | # define UINT16_C(c) c |
294 | # define UINT32_C(c) c ## U |
295 | # if __WORDSIZE == 64 |
296 | # define UINT64_C(c) c ## UL |
297 | # else |
298 | # define UINT64_C(c) c ## ULL |
299 | # endif |
300 | |
301 | /* Maximal type. */ |
302 | # if __WORDSIZE == 64 |
303 | # define INTMAX_C(c) c ## L |
304 | # define UINTMAX_C(c) c ## UL |
305 | # else |
306 | # define INTMAX_C(c) c ## LL |
307 | # define UINTMAX_C(c) c ## ULL |
308 | # endif |
309 | |
310 | #if __GLIBC_USE (IEC_60559_BFP_EXT) |
311 | |
312 | # define INT8_WIDTH 8 |
313 | # define UINT8_WIDTH 8 |
314 | # define INT16_WIDTH 16 |
315 | # define UINT16_WIDTH 16 |
316 | # define INT32_WIDTH 32 |
317 | # define UINT32_WIDTH 32 |
318 | # define INT64_WIDTH 64 |
319 | # define UINT64_WIDTH 64 |
320 | |
321 | # define INT_LEAST8_WIDTH 8 |
322 | # define UINT_LEAST8_WIDTH 8 |
323 | # define INT_LEAST16_WIDTH 16 |
324 | # define UINT_LEAST16_WIDTH 16 |
325 | # define INT_LEAST32_WIDTH 32 |
326 | # define UINT_LEAST32_WIDTH 32 |
327 | # define INT_LEAST64_WIDTH 64 |
328 | # define UINT_LEAST64_WIDTH 64 |
329 | |
330 | # define INT_FAST8_WIDTH 8 |
331 | # define UINT_FAST8_WIDTH 8 |
332 | # define INT_FAST16_WIDTH __WORDSIZE |
333 | # define UINT_FAST16_WIDTH __WORDSIZE |
334 | # define INT_FAST32_WIDTH __WORDSIZE |
335 | # define UINT_FAST32_WIDTH __WORDSIZE |
336 | # define INT_FAST64_WIDTH 64 |
337 | # define UINT_FAST64_WIDTH 64 |
338 | |
339 | # define INTPTR_WIDTH __WORDSIZE |
340 | # define UINTPTR_WIDTH __WORDSIZE |
341 | |
342 | # define INTMAX_WIDTH 64 |
343 | # define UINTMAX_WIDTH 64 |
344 | |
345 | # define PTRDIFF_WIDTH __WORDSIZE |
346 | # define SIG_ATOMIC_WIDTH 32 |
347 | # define SIZE_WIDTH __WORDSIZE |
348 | # define WCHAR_WIDTH 32 |
349 | # define WINT_WIDTH 32 |
350 | |
351 | #endif |
352 | |
353 | #endif /* stdint.h */ |
354 | |