1 | /* Copyright (C) 1997,1998,1999,2000,2001,2006 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 | #include <features.h> |
26 | #include <bits/wchar.h> |
27 | #include <bits/wordsize.h> |
28 | |
29 | /* Exact integral types. */ |
30 | |
31 | /* Signed. */ |
32 | |
33 | /* There is some amount of overlap with <sys/types.h> as known by inet code */ |
34 | #ifndef __int8_t_defined |
35 | # define __int8_t_defined |
36 | typedef signed char int8_t; |
37 | typedef short int int16_t; |
38 | typedef int int32_t; |
39 | # if __WORDSIZE == 64 |
40 | typedef long int int64_t; |
41 | # else |
42 | __extension__ |
43 | typedef long long int int64_t; |
44 | # endif |
45 | #endif |
46 | |
47 | /* Unsigned. */ |
48 | typedef unsigned char uint8_t; |
49 | typedef unsigned short int uint16_t; |
50 | #ifndef __uint32_t_defined |
51 | typedef unsigned int uint32_t; |
52 | # define __uint32_t_defined |
53 | #endif |
54 | #if __WORDSIZE == 64 |
55 | typedef unsigned long int uint64_t; |
56 | #else |
57 | __extension__ |
58 | typedef unsigned long long int uint64_t; |
59 | #endif |
60 | |
61 | |
62 | /* Small types. */ |
63 | |
64 | /* Signed. */ |
65 | typedef signed char int_least8_t; |
66 | typedef short int int_least16_t; |
67 | typedef int int_least32_t; |
68 | #if __WORDSIZE == 64 |
69 | typedef long int int_least64_t; |
70 | #else |
71 | __extension__ |
72 | typedef long long int int_least64_t; |
73 | #endif |
74 | |
75 | /* Unsigned. */ |
76 | typedef unsigned char uint_least8_t; |
77 | typedef unsigned short int uint_least16_t; |
78 | typedef unsigned int uint_least32_t; |
79 | #if __WORDSIZE == 64 |
80 | typedef unsigned long int uint_least64_t; |
81 | #else |
82 | __extension__ |
83 | typedef unsigned long long int uint_least64_t; |
84 | #endif |
85 | |
86 | |
87 | /* Fast types. */ |
88 | |
89 | /* Signed. */ |
90 | typedef signed char int_fast8_t; |
91 | #if __WORDSIZE == 64 |
92 | typedef long int int_fast16_t; |
93 | typedef long int int_fast32_t; |
94 | typedef long int int_fast64_t; |
95 | #else |
96 | typedef int int_fast16_t; |
97 | typedef int int_fast32_t; |
98 | __extension__ |
99 | typedef long long int int_fast64_t; |
100 | #endif |
101 | |
102 | /* Unsigned. */ |
103 | typedef unsigned char uint_fast8_t; |
104 | #if __WORDSIZE == 64 |
105 | typedef unsigned long int uint_fast16_t; |
106 | typedef unsigned long int uint_fast32_t; |
107 | typedef unsigned long int uint_fast64_t; |
108 | #else |
109 | typedef unsigned int uint_fast16_t; |
110 | typedef unsigned int uint_fast32_t; |
111 | __extension__ |
112 | typedef unsigned long long int uint_fast64_t; |
113 | #endif |
114 | |
115 | |
116 | /* Types for `void *' pointers. */ |
117 | #if __WORDSIZE == 64 |
118 | # ifndef __intptr_t_defined |
119 | typedef long int intptr_t; |
120 | # define __intptr_t_defined |
121 | # endif |
122 | typedef unsigned long int uintptr_t; |
123 | #else |
124 | # ifndef __intptr_t_defined |
125 | typedef int intptr_t; |
126 | # define __intptr_t_defined |
127 | # endif |
128 | typedef unsigned int uintptr_t; |
129 | #endif |
130 | |
131 | |
132 | /* Largest integral types. */ |
133 | #if __WORDSIZE == 64 |
134 | typedef long int intmax_t; |
135 | typedef unsigned long int uintmax_t; |
136 | #else |
137 | __extension__ |
138 | typedef long long int intmax_t; |
139 | __extension__ |
140 | typedef unsigned long long int uintmax_t; |
141 | #endif |
142 | |
143 | |
144 | /* The ISO C99 standard specifies that in C++ implementations these |
145 | macros should only be defined if explicitly requested. */ |
146 | #if !defined __cplusplus || defined __STDC_LIMIT_MACROS |
147 | |
148 | # if __WORDSIZE == 64 |
149 | # define __INT64_C(c) c ## L |
150 | # define __UINT64_C(c) c ## UL |
151 | # else |
152 | # define __INT64_C(c) c ## LL |
153 | # define __UINT64_C(c) c ## ULL |
154 | # endif |
155 | |
156 | /* Limits of integral types. */ |
157 | |
158 | /* Minimum of signed integral types. */ |
159 | # define INT8_MIN (-128) |
160 | # define INT16_MIN (-32767-1) |
161 | # define INT32_MIN (-2147483647-1) |
162 | # define INT64_MIN (-__INT64_C(9223372036854775807)-1) |
163 | /* Maximum of signed integral types. */ |
164 | # define INT8_MAX (127) |
165 | # define INT16_MAX (32767) |
166 | # define INT32_MAX (2147483647) |
167 | # define INT64_MAX (__INT64_C(9223372036854775807)) |
168 | |
169 | /* Maximum of unsigned integral types. */ |
170 | # define UINT8_MAX (255) |
171 | # define UINT16_MAX (65535) |
172 | # define UINT32_MAX (4294967295U) |
173 | # define UINT64_MAX (__UINT64_C(18446744073709551615)) |
174 | |
175 | |
176 | /* Minimum of signed integral types having a minimum size. */ |
177 | # define INT_LEAST8_MIN (-128) |
178 | # define INT_LEAST16_MIN (-32767-1) |
179 | # define INT_LEAST32_MIN (-2147483647-1) |
180 | # define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1) |
181 | /* Maximum of signed integral types having a minimum size. */ |
182 | # define INT_LEAST8_MAX (127) |
183 | # define INT_LEAST16_MAX (32767) |
184 | # define INT_LEAST32_MAX (2147483647) |
185 | # define INT_LEAST64_MAX (__INT64_C(9223372036854775807)) |
186 | |
187 | /* Maximum of unsigned integral types having a minimum size. */ |
188 | # define UINT_LEAST8_MAX (255) |
189 | # define UINT_LEAST16_MAX (65535) |
190 | # define UINT_LEAST32_MAX (4294967295U) |
191 | # define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615)) |
192 | |
193 | |
194 | /* Minimum of fast signed integral types having a minimum size. */ |
195 | # define INT_FAST8_MIN (-128) |
196 | # if __WORDSIZE == 64 |
197 | # define INT_FAST16_MIN (-9223372036854775807L-1) |
198 | # define INT_FAST32_MIN (-9223372036854775807L-1) |
199 | # else |
200 | # define INT_FAST16_MIN (-2147483647-1) |
201 | # define INT_FAST32_MIN (-2147483647-1) |
202 | # endif |
203 | # define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1) |
204 | /* Maximum of fast signed integral types having a minimum size. */ |
205 | # define INT_FAST8_MAX (127) |
206 | # if __WORDSIZE == 64 |
207 | # define INT_FAST16_MAX (9223372036854775807L) |
208 | # define INT_FAST32_MAX (9223372036854775807L) |
209 | # else |
210 | # define INT_FAST16_MAX (2147483647) |
211 | # define INT_FAST32_MAX (2147483647) |
212 | # endif |
213 | # define INT_FAST64_MAX (__INT64_C(9223372036854775807)) |
214 | |
215 | /* Maximum of fast unsigned integral types having a minimum size. */ |
216 | # define UINT_FAST8_MAX (255) |
217 | # if __WORDSIZE == 64 |
218 | # define UINT_FAST16_MAX (18446744073709551615UL) |
219 | # define UINT_FAST32_MAX (18446744073709551615UL) |
220 | # else |
221 | # define UINT_FAST16_MAX (4294967295U) |
222 | # define UINT_FAST32_MAX (4294967295U) |
223 | # endif |
224 | # define UINT_FAST64_MAX (__UINT64_C(18446744073709551615)) |
225 | |
226 | |
227 | /* Values to test for integral types holding `void *' pointer. */ |
228 | # if __WORDSIZE == 64 |
229 | # define INTPTR_MIN (-9223372036854775807L-1) |
230 | # define INTPTR_MAX (9223372036854775807L) |
231 | # define UINTPTR_MAX (18446744073709551615UL) |
232 | # else |
233 | # define INTPTR_MIN (-2147483647-1) |
234 | # define INTPTR_MAX (2147483647) |
235 | # define UINTPTR_MAX (4294967295U) |
236 | # endif |
237 | |
238 | |
239 | /* Minimum for largest signed integral type. */ |
240 | # define INTMAX_MIN (-__INT64_C(9223372036854775807)-1) |
241 | /* Maximum for largest signed integral type. */ |
242 | # define INTMAX_MAX (__INT64_C(9223372036854775807)) |
243 | |
244 | /* Maximum for largest unsigned integral type. */ |
245 | # define UINTMAX_MAX (__UINT64_C(18446744073709551615)) |
246 | |
247 | |
248 | /* Limits of other integer types. */ |
249 | |
250 | /* Limits of `ptrdiff_t' type. */ |
251 | # if __WORDSIZE == 64 |
252 | # define PTRDIFF_MIN (-9223372036854775807L-1) |
253 | # define PTRDIFF_MAX (9223372036854775807L) |
254 | # else |
255 | # define PTRDIFF_MIN (-2147483647-1) |
256 | # define PTRDIFF_MAX (2147483647) |
257 | # endif |
258 | |
259 | /* Limits of `sig_atomic_t'. */ |
260 | # define SIG_ATOMIC_MIN (-2147483647-1) |
261 | # define SIG_ATOMIC_MAX (2147483647) |
262 | |
263 | /* Limit of `size_t' type. */ |
264 | # if __WORDSIZE == 64 |
265 | # define SIZE_MAX (18446744073709551615UL) |
266 | # else |
267 | # define SIZE_MAX (4294967295U) |
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 | #endif /* C++ && limit macros */ |
282 | |
283 | |
284 | /* The ISO C99 standard specifies that in C++ implementations these |
285 | should only be defined if explicitly requested. */ |
286 | #if !defined __cplusplus || defined __STDC_CONSTANT_MACROS |
287 | |
288 | /* Signed. */ |
289 | # define INT8_C(c) c |
290 | # define INT16_C(c) c |
291 | # define INT32_C(c) c |
292 | # if __WORDSIZE == 64 |
293 | # define INT64_C(c) c ## L |
294 | # else |
295 | # define INT64_C(c) c ## LL |
296 | # endif |
297 | |
298 | /* Unsigned. */ |
299 | # define UINT8_C(c) c |
300 | # define UINT16_C(c) c |
301 | # define UINT32_C(c) c ## U |
302 | # if __WORDSIZE == 64 |
303 | # define UINT64_C(c) c ## UL |
304 | # else |
305 | # define UINT64_C(c) c ## ULL |
306 | # endif |
307 | |
308 | /* Maximal type. */ |
309 | # if __WORDSIZE == 64 |
310 | # define INTMAX_C(c) c ## L |
311 | # define UINTMAX_C(c) c ## UL |
312 | # else |
313 | # define INTMAX_C(c) c ## LL |
314 | # define UINTMAX_C(c) c ## ULL |
315 | # endif |
316 | |
317 | #endif /* C++ && constant macros */ |
318 | |
319 | #endif /* stdint.h */ |
320 | |