Rev 1693 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1693 | Rev 2168 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2004, 2005 by |
2 | * Copyright (c) 2004, 2005 by |
3 | * Ralf Corsepius, Ulm/Germany. All rights reserved. |
3 | * Ralf Corsepius, Ulm/Germany. All rights reserved. |
4 | * |
4 | * |
5 | * Permission to use, copy, modify, and distribute this software |
5 | * Permission to use, copy, modify, and distribute this software |
6 | * is freely granted, provided that this notice is preserved. |
6 | * is freely granted, provided that this notice is preserved. |
7 | */ |
7 | */ |
8 | 8 | ||
9 | #ifndef _STDINT_H |
9 | #ifndef _STDINT_H |
10 | #define _STDINT_H |
10 | #define _STDINT_H |
11 | 11 | ||
12 | #ifdef __cplusplus |
12 | #ifdef __cplusplus |
13 | extern "C" { |
13 | extern "C" { |
14 | #endif |
14 | #endif |
15 | 15 | ||
16 | #if defined(__GNUC__) && \ |
16 | #if defined(__GNUC__) && \ |
17 | ( (__GNUC__ >= 4) || \ |
17 | ( (__GNUC__ >= 4) || \ |
18 | ( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2) ) ) |
18 | ( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2) ) ) |
19 | /* gcc > 3.2 implicitly defines the values we are interested */ |
19 | /* gcc > 3.2 implicitly defines the values we are interested */ |
20 | #define __STDINT_EXP(x) __##x##__ |
20 | #define __STDINT_EXP(x) __##x##__ |
21 | #else |
21 | #else |
22 | #define __STDINT_EXP(x) x |
22 | #define __STDINT_EXP(x) x |
23 | #include |
23 | #include |
24 | #endif |
24 | #endif |
25 | 25 | ||
26 | /* Check if "long long" is 64bit wide */ |
26 | /* Check if "long long" is 64bit wide */ |
27 | /* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */ |
27 | /* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */ |
28 | #if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \ |
28 | #if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \ |
29 | || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) ) |
29 | || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) ) |
30 | #define __have_longlong64 1 |
30 | #define __have_longlong64 1 |
31 | #endif |
31 | #endif |
32 | 32 | ||
33 | /* Check if "long" is 64bit or 32bit wide */ |
33 | /* Check if "long" is 64bit or 32bit wide */ |
34 | #if __STDINT_EXP(LONG_MAX) > 0x7fffffff |
34 | #if __STDINT_EXP(LONG_MAX) > 0x7fffffff |
35 | #define __have_long64 1 |
35 | #define __have_long64 1 |
36 | #elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) |
36 | #elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) |
37 | #define __have_long32 1 |
37 | #define __have_long32 1 |
38 | #define __have_long64 0 |
- | |
39 | #endif |
38 | #endif |
40 | 39 | ||
41 | #if __STDINT_EXP(SCHAR_MAX) == 0x7f |
40 | #if __STDINT_EXP(SCHAR_MAX) == 0x7f |
42 | typedef signed char int8_t ; |
41 | typedef signed char int8_t ; |
43 | typedef unsigned char uint8_t ; |
42 | typedef unsigned char uint8_t ; |
44 | #define __int8_t_defined 1 |
43 | #define __int8_t_defined 1 |
45 | #endif |
44 | #endif |
46 | 45 | ||
47 | #if __int8_t_defined |
46 | #if __int8_t_defined |
48 | typedef signed char int_least8_t; |
47 | typedef signed char int_least8_t; |
49 | typedef unsigned char uint_least8_t; |
48 | typedef unsigned char uint_least8_t; |
50 | #define __int_least8_t_defined 1 |
49 | #define __int_least8_t_defined 1 |
51 | #endif |
50 | #endif |
52 | 51 | ||
53 | #if __STDINT_EXP(SHRT_MAX) == 0x7fff |
52 | #if __STDINT_EXP(SHRT_MAX) == 0x7fff |
54 | typedef signed short int16_t; |
53 | typedef signed short int16_t; |
55 | typedef unsigned short uint16_t; |
54 | typedef unsigned short uint16_t; |
56 | #define __int16_t_defined 1 |
55 | #define __int16_t_defined 1 |
57 | #elif __STDINT_EXP(INT_MAX) == 0x7fff |
56 | #elif __STDINT_EXP(INT_MAX) == 0x7fff |
58 | typedef signed int int16_t; |
57 | typedef signed int int16_t; |
59 | typedef unsigned int uint16_t; |
58 | typedef unsigned int uint16_t; |
60 | #define __int16_t_defined 1 |
59 | #define __int16_t_defined 1 |
61 | #elif __STDINT_EXP(SCHAR_MAX) == 0x7fff |
60 | #elif __STDINT_EXP(SCHAR_MAX) == 0x7fff |
62 | typedef signed char int16_t; |
61 | typedef signed char int16_t; |
63 | typedef unsigned char uint16_t; |
62 | typedef unsigned char uint16_t; |
64 | #define __int16_t_defined 1 |
63 | #define __int16_t_defined 1 |
65 | #endif |
64 | #endif |
66 | 65 | ||
67 | #if __int16_t_defined |
66 | #if __int16_t_defined |
68 | typedef int16_t int_least16_t; |
67 | typedef int16_t int_least16_t; |
69 | typedef uint16_t uint_least16_t; |
68 | typedef uint16_t uint_least16_t; |
70 | #define __int_least16_t_defined 1 |
69 | #define __int_least16_t_defined 1 |
71 | 70 | ||
72 | #if !__int_least8_t_defined |
71 | #if !__int_least8_t_defined |
73 | typedef int16_t int_least8_t; |
72 | typedef int16_t int_least8_t; |
74 | typedef uint16_t uint_least8_t; |
73 | typedef uint16_t uint_least8_t; |
75 | #define __int_least8_t_defined 1 |
74 | #define __int_least8_t_defined 1 |
76 | #endif |
75 | #endif |
77 | #endif |
76 | #endif |
78 | 77 | ||
79 | #if __have_long32 |
78 | //#if __have_long32 |
80 | typedef signed long int32_t; |
79 | //typedef signed long int32_t; |
81 | typedef unsigned long uint32_t; |
80 | //typedef unsigned long uint32_t; |
82 | #define __int32_t_defined 1 |
81 | //#define __int32_t_defined 1 |
83 | #elif __STDINT_EXP(INT_MAX) == 0x7fffffffL |
82 | //#elif __STDINT_EXP(INT_MAX) == 0x7fffffffL |
84 | typedef signed int int32_t; |
83 | typedef signed int int32_t; |
85 | typedef unsigned int uint32_t; |
84 | typedef unsigned int uint32_t; |
86 | #define __int32_t_defined 1 |
85 | #define __int32_t_defined 1 |
87 | #elif __STDINT_EXP(SHRT_MAX) == 0x7fffffffL |
86 | //#elif __STDINT_EXP(SHRT_MAX) == 0x7fffffffL |
88 | typedef signed short int32_t; |
87 | //typedef signed short int32_t; |
89 | typedef unsigned short uint32_t; |
88 | //typedef unsigned short uint32_t; |
90 | #define __int32_t_defined 1 |
89 | //#define __int32_t_defined 1 |
91 | #elif __STDINT_EXP(SCHAR_MAX) == 0x7fffffffL |
90 | //#elif __STDINT_EXP(SCHAR_MAX) == 0x7fffffffL |
92 | typedef signed char int32_t; |
91 | //typedef signed char int32_t; |
93 | typedef unsigned char uint32_t; |
92 | //typedef unsigned char uint32_t; |
94 | #define __int32_t_defined 1 |
93 | //#define __int32_t_defined 1 |
95 | #endif |
94 | //#endif |
96 | 95 | ||
97 | #if __int32_t_defined |
96 | #if __int32_t_defined |
98 | typedef int32_t int_least32_t; |
97 | typedef int32_t int_least32_t; |
99 | typedef uint32_t uint_least32_t; |
98 | typedef uint32_t uint_least32_t; |
100 | #define __int_least32_t_defined 1 |
99 | #define __int_least32_t_defined 1 |
101 | 100 | ||
102 | #if !__int_least8_t_defined |
101 | #if !__int_least8_t_defined |
103 | typedef int32_t int_least8_t; |
102 | typedef int32_t int_least8_t; |
104 | typedef uint32_t uint_least8_t; |
103 | typedef uint32_t uint_least8_t; |
105 | #define __int_least8_t_defined 1 |
104 | #define __int_least8_t_defined 1 |
106 | #endif |
105 | #endif |
107 | 106 | ||
108 | #if !__int_least16_t_defined |
107 | #if !__int_least16_t_defined |
109 | typedef int32_t int_least16_t; |
108 | typedef int32_t int_least16_t; |
110 | typedef uint32_t uint_least16_t; |
109 | typedef uint32_t uint_least16_t; |
111 | #define __int_least16_t_defined 1 |
110 | #define __int_least16_t_defined 1 |
112 | #endif |
111 | #endif |
113 | #endif |
112 | #endif |
114 | 113 | ||
115 | #if __have_long64 |
114 | #if __have_long64 |
116 | typedef signed long int64_t; |
115 | typedef signed long int64_t; |
117 | typedef unsigned long uint64_t; |
116 | typedef unsigned long uint64_t; |
118 | #define __int64_t_defined 1 |
117 | #define __int64_t_defined 1 |
119 | #elif __have_longlong64 |
118 | #elif __have_longlong64 |
120 | typedef signed long long int64_t; |
119 | typedef signed long long int64_t; |
121 | typedef unsigned long long uint64_t; |
120 | typedef unsigned long long uint64_t; |
122 | #define __int64_t_defined 1 |
121 | #define __int64_t_defined 1 |
123 | #elif __STDINT_EXP(INT_MAX) > 0x7fffffff |
122 | #elif __STDINT_EXP(INT_MAX) > 0x7fffffff |
124 | typedef signed int int64_t; |
123 | typedef signed int int64_t; |
125 | typedef unsigned int uint64_t; |
124 | typedef unsigned int uint64_t; |
126 | #define __int64_t_defined 1 |
125 | #define __int64_t_defined 1 |
127 | #endif |
126 | #endif |
128 | 127 | ||
129 | #if __int64_t_defined |
128 | #if __int64_t_defined |
130 | typedef int64_t int_least64_t; |
129 | typedef int64_t int_least64_t; |
131 | typedef uint64_t uint_least64_t; |
130 | typedef uint64_t uint_least64_t; |
132 | #define __int_least64_t_defined 1 |
131 | #define __int_least64_t_defined 1 |
133 | 132 | ||
134 | #if !__int_least8_t_defined |
133 | #if !__int_least8_t_defined |
135 | typedef int64_t int_least8_t; |
134 | typedef int64_t int_least8_t; |
136 | typedef uint64_t uint_least8_t; |
135 | typedef uint64_t uint_least8_t; |
137 | #define __int_least8_t_defined 1 |
136 | #define __int_least8_t_defined 1 |
138 | #endif |
137 | #endif |
139 | 138 | ||
140 | #if !__int_least16_t_defined |
139 | #if !__int_least16_t_defined |
141 | typedef int64_t int_least16_t; |
140 | typedef int64_t int_least16_t; |
142 | typedef uint64_t uint_least16_t; |
141 | typedef uint64_t uint_least16_t; |
143 | #define __int_least16_t_defined 1 |
142 | #define __int_least16_t_defined 1 |
144 | #endif |
143 | #endif |
145 | 144 | ||
146 | #if !__int_least32_t_defined |
145 | #if !__int_least32_t_defined |
147 | typedef int64_t int_least32_t; |
146 | typedef int64_t int_least32_t; |
148 | typedef uint64_t uint_least32_t; |
147 | typedef uint64_t uint_least32_t; |
149 | #define __int_least32_t_defined 1 |
148 | #define __int_least32_t_defined 1 |
150 | #endif |
149 | #endif |
151 | #endif |
150 | #endif |
152 | 151 | ||
153 | /* |
152 | /* |
154 | * Fastest minimum-width integer types |
153 | * Fastest minimum-width integer types |
155 | * |
154 | * |
156 | * Assume int to be the fastest type for all types with a width |
155 | * Assume int to be the fastest type for all types with a width |
157 | * less than __INT_MAX__ rsp. INT_MAX |
156 | * less than __INT_MAX__ rsp. INT_MAX |
158 | */ |
157 | */ |
159 | #if __STDINT_EXP(INT_MAX) >= 0x7f |
158 | #if __STDINT_EXP(INT_MAX) >= 0x7f |
160 | typedef signed int int_fast8_t; |
159 | typedef signed int int_fast8_t; |
161 | typedef unsigned int uint_fast8_t; |
160 | typedef unsigned int uint_fast8_t; |
162 | #define __int_fast8_t_defined 1 |
161 | #define __int_fast8_t_defined 1 |
163 | #endif |
162 | #endif |
164 | 163 | ||
165 | #if __STDINT_EXP(INT_MAX) >= 0x7fff |
164 | #if __STDINT_EXP(INT_MAX) >= 0x7fff |
166 | typedef signed int int_fast16_t; |
165 | typedef signed int int_fast16_t; |
167 | typedef unsigned int uint_fast16_t; |
166 | typedef unsigned int uint_fast16_t; |
168 | #define __int_fast16_t_defined 1 |
167 | #define __int_fast16_t_defined 1 |
169 | #endif |
168 | #endif |
170 | 169 | ||
171 | #if __STDINT_EXP(INT_MAX) >= 0x7fffffff |
170 | #if __STDINT_EXP(INT_MAX) >= 0x7fffffff |
172 | typedef signed int int_fast32_t; |
171 | typedef signed int int_fast32_t; |
173 | typedef unsigned int uint_fast32_t; |
172 | typedef unsigned int uint_fast32_t; |
174 | #define __int_fast32_t_defined 1 |
173 | #define __int_fast32_t_defined 1 |
175 | #endif |
174 | #endif |
176 | 175 | ||
177 | #if __STDINT_EXP(INT_MAX) > 0x7fffffff |
176 | #if __STDINT_EXP(INT_MAX) > 0x7fffffff |
178 | typedef signed int int_fast64_t; |
177 | typedef signed int int_fast64_t; |
179 | typedef unsigned int uint_fast64_t; |
178 | typedef unsigned int uint_fast64_t; |
180 | #define __int_fast64_t_defined 1 |
179 | #define __int_fast64_t_defined 1 |
181 | #else |
- | |
182 | #define __int_fast64_t_defined 0 |
- | |
183 | #endif |
180 | #endif |
184 | 181 | ||
185 | /* |
182 | /* |
186 | * Fall back to [u]int_least |
183 | * Fall back to [u]int_least |
187 | * not having been defined, yet. |
184 | * not having been defined, yet. |
188 | * Leave undefined, if [u]int_least |
185 | * Leave undefined, if [u]int_least |
189 | */ |
186 | */ |
190 | #if !__int_fast8_t_defined |
187 | #if !__int_fast8_t_defined |
191 | #if __int_least8_t_defined |
188 | #if __int_least8_t_defined |
192 | typedef int_least8_t int_fast8_t; |
189 | typedef int_least8_t int_fast8_t; |
193 | typedef uint_least8_t uint_fast8_t; |
190 | typedef uint_least8_t uint_fast8_t; |
194 | #define __int_fast8_t_defined 1 |
191 | #define __int_fast8_t_defined 1 |
195 | #endif |
192 | #endif |
196 | #endif |
193 | #endif |
197 | 194 | ||
198 | #if !__int_fast16_t_defined |
195 | #if !__int_fast16_t_defined |
199 | #if __int_least16_t_defined |
196 | #if __int_least16_t_defined |
200 | typedef int_least16_t int_fast16_t; |
197 | typedef int_least16_t int_fast16_t; |
201 | typedef uint_least16_t uint_fast16_t; |
198 | typedef uint_least16_t uint_fast16_t; |
202 | #define __int_fast16_t_defined 1 |
199 | #define __int_fast16_t_defined 1 |
203 | #endif |
200 | #endif |
204 | #endif |
201 | #endif |
205 | 202 | ||
206 | #if !__int_fast32_t_defined |
203 | #if !__int_fast32_t_defined |
207 | #if __int_least32_t_defined |
204 | #if __int_least32_t_defined |
208 | typedef int_least32_t int_fast32_t; |
205 | typedef int_least32_t int_fast32_t; |
209 | typedef uint_least32_t uint_fast32_t; |
206 | typedef uint_least32_t uint_fast32_t; |
210 | #define __int_fast32_t_defined 1 |
207 | #define __int_fast32_t_defined 1 |
211 | #endif |
208 | #endif |
212 | #endif |
209 | #endif |
213 | 210 | ||
214 | #if !__int_fast64_t_defined |
211 | #if !__int_fast64_t_defined |
215 | #if __int_least64_t_defined |
212 | #if __int_least64_t_defined |
216 | typedef int_least64_t int_fast64_t; |
213 | typedef int_least64_t int_fast64_t; |
217 | typedef uint_least64_t uint_fast64_t; |
214 | typedef uint_least64_t uint_fast64_t; |
218 | #undef __int_fast64_t_defined |
- | |
219 | #define __int_fast64_t_defined 1 |
215 | #define __int_fast64_t_defined 1 |
220 | #endif |
216 | #endif |
221 | #endif |
217 | #endif |
222 | 218 | ||
223 | /* Greatest-width integer types */ |
219 | /* Greatest-width integer types */ |
224 | /* Modern GCCs provide __INTMAX_TYPE__ */ |
220 | /* Modern GCCs provide __INTMAX_TYPE__ */ |
225 | #if defined(__INTMAX_TYPE__) |
221 | #if defined(__INTMAX_TYPE__) |
226 | typedef __INTMAX_TYPE__ intmax_t; |
222 | typedef __INTMAX_TYPE__ intmax_t; |
227 | #elif __have_longlong64 |
223 | #elif __have_longlong64 |
228 | typedef signed long long intmax_t; |
224 | typedef signed long long intmax_t; |
229 | #else |
225 | #else |
230 | typedef signed long intmax_t; |
226 | typedef signed long intmax_t; |
231 | #endif |
227 | #endif |
232 | 228 | ||
233 | /* Modern GCCs provide __UINTMAX_TYPE__ */ |
229 | /* Modern GCCs provide __UINTMAX_TYPE__ */ |
234 | #if defined(__UINTMAX_TYPE__) |
230 | #if defined(__UINTMAX_TYPE__) |
235 | typedef __UINTMAX_TYPE__ uintmax_t; |
231 | typedef __UINTMAX_TYPE__ uintmax_t; |
236 | #elif __have_longlong64 |
232 | #elif __have_longlong64 |
237 | typedef unsigned long long uintmax_t; |
233 | typedef unsigned long long uintmax_t; |
238 | #else |
234 | #else |
239 | typedef unsigned long uintmax_t; |
235 | typedef unsigned long uintmax_t; |
240 | #endif |
236 | #endif |
241 | 237 | ||
242 | /* |
238 | /* |
243 | * GCC doesn't provide an appropriate macro for [u]intptr_t |
239 | * GCC doesn't provide an appropriate macro for [u]intptr_t |
244 | * For now, use __PTRDIFF_TYPE__ |
240 | * For now, use __PTRDIFF_TYPE__ |
245 | */ |
241 | */ |
246 | #if defined(__PTRDIFF_TYPE__) |
242 | #if defined(__PTRDIFF_TYPE__) |
247 | typedef signed __PTRDIFF_TYPE__ intptr_t; |
243 | typedef signed __PTRDIFF_TYPE__ intptr_t; |
248 | typedef unsigned __PTRDIFF_TYPE__ uintptr_t; |
244 | typedef unsigned __PTRDIFF_TYPE__ uintptr_t; |
249 | #define INTPTR_MAX PTRDIFF_MAX |
245 | #define INTPTR_MAX PTRDIFF_MAX |
250 | #define INTPTR_MIN PTRDIFF_MIN |
246 | #define INTPTR_MIN PTRDIFF_MIN |
251 | #ifdef __UINTPTR_MAX__ |
247 | #ifdef __UINTPTR_MAX__ |
252 | #define UINTPTR_MAX __UINTPTR_MAX__ |
248 | #define UINTPTR_MAX __UINTPTR_MAX__ |
253 | #else |
249 | #else |
254 | #define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1) |
250 | #define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1) |
255 | #endif |
251 | #endif |
256 | #else |
252 | #else |
257 | /* |
253 | /* |
258 | * Fallback to hardcoded values, |
254 | * Fallback to hardcoded values, |
259 | * should be valid on cpu's with 32bit int/32bit void* |
255 | * should be valid on cpu's with 32bit int/32bit void* |
260 | */ |
256 | */ |
261 | typedef signed long intptr_t; |
257 | typedef signed long intptr_t; |
262 | typedef unsigned long uintptr_t; |
258 | typedef unsigned long uintptr_t; |
263 | #define INTPTR_MAX __STDINT_EXP(LONG_MAX) |
259 | #define INTPTR_MAX __STDINT_EXP(LONG_MAX) |
264 | #define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1) |
260 | #define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1) |
265 | #define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) |
261 | #define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) |
266 | #endif |
262 | #endif |
267 | 263 | ||
268 | /* Limits of Specified-Width Integer Types */ |
264 | /* Limits of Specified-Width Integer Types */ |
269 | 265 | ||
270 | #if __int8_t_defined |
266 | #if __int8_t_defined |
271 | #define INT8_MIN -128 |
267 | #define INT8_MIN -128 |
272 | #define INT8_MAX 127 |
268 | #define INT8_MAX 127 |
273 | #define UINT8_MAX 255 |
269 | #define UINT8_MAX 255 |
274 | #endif |
270 | #endif |
275 | 271 | ||
276 | #if __int_least8_t_defined |
272 | #if __int_least8_t_defined |
277 | #define INT_LEAST8_MIN -128 |
273 | #define INT_LEAST8_MIN -128 |
278 | #define INT_LEAST8_MAX 127 |
274 | #define INT_LEAST8_MAX 127 |
279 | #define UINT_LEAST8_MAX 255 |
275 | #define UINT_LEAST8_MAX 255 |
280 | #else |
276 | #else |
281 | #error required type int_least8_t missing |
277 | #error required type int_least8_t missing |
282 | #endif |
278 | #endif |
283 | 279 | ||
284 | #if __int16_t_defined |
280 | #if __int16_t_defined |
285 | #define INT16_MIN -32768 |
281 | #define INT16_MIN -32768 |
286 | #define INT16_MAX 32767 |
282 | #define INT16_MAX 32767 |
287 | #define UINT16_MAX 65535 |
283 | #define UINT16_MAX 65535 |
288 | #endif |
284 | #endif |
289 | 285 | ||
290 | #if __int_least16_t_defined |
286 | #if __int_least16_t_defined |
291 | #define INT_LEAST16_MIN -32768 |
287 | #define INT_LEAST16_MIN -32768 |
292 | #define INT_LEAST16_MAX 32767 |
288 | #define INT_LEAST16_MAX 32767 |
293 | #define UINT_LEAST16_MAX 65535 |
289 | #define UINT_LEAST16_MAX 65535 |
294 | #else |
290 | #else |
295 | #error required type int_least16_t missing |
291 | #error required type int_least16_t missing |
296 | #endif |
292 | #endif |
297 | 293 | ||
298 | #if __int32_t_defined |
294 | #if __int32_t_defined |
299 | #if __have_long32 |
295 | #if __have_long32 |
300 | #define INT32_MIN (-2147483647L-1) |
296 | #define INT32_MIN (-2147483647L-1) |
301 | #define INT32_MAX 2147483647L |
297 | #define INT32_MAX 2147483647L |
302 | #define UINT32_MAX 4294967295UL |
298 | #define UINT32_MAX 4294967295UL |
303 | #else |
299 | #else |
304 | #define INT32_MIN (-2147483647-1) |
300 | #define INT32_MIN (-2147483647-1) |
305 | #define INT32_MAX 2147483647 |
301 | #define INT32_MAX 2147483647 |
306 | #define UINT32_MAX 4294967295U |
302 | #define UINT32_MAX 4294967295U |
307 | #endif |
303 | #endif |
308 | #endif |
304 | #endif |
309 | 305 | ||
310 | #if __int_least32_t_defined |
306 | #if __int_least32_t_defined |
311 | #if __have_long32 |
307 | #if __have_long32 |
312 | #define INT_LEAST32_MIN (-2147483647L-1) |
308 | #define INT_LEAST32_MIN (-2147483647L-1) |
313 | #define INT_LEAST32_MAX 2147483647L |
309 | #define INT_LEAST32_MAX 2147483647L |
314 | #define UINT_LEAST32_MAX 4294967295UL |
310 | #define UINT_LEAST32_MAX 4294967295UL |
315 | #else |
311 | #else |
316 | #define INT_LEAST32_MIN (-2147483647-1) |
312 | #define INT_LEAST32_MIN (-2147483647-1) |
317 | #define INT_LEAST32_MAX 2147483647 |
313 | #define INT_LEAST32_MAX 2147483647 |
318 | #define UINT_LEAST32_MAX 4294967295U |
314 | #define UINT_LEAST32_MAX 4294967295U |
319 | #endif |
315 | #endif |
320 | #else |
316 | #else |
321 | #error required type int_least32_t missing |
317 | #error required type int_least32_t missing |
322 | #endif |
318 | #endif |
323 | 319 | ||
324 | #if __int64_t_defined |
320 | #if __int64_t_defined |
325 | #if __have_long64 |
321 | #if __have_long64 |
326 | #define INT64_MIN (-9223372036854775807L-1L) |
322 | #define INT64_MIN (-9223372036854775807L-1L) |
327 | #define INT64_MAX 9223372036854775807L |
323 | #define INT64_MAX 9223372036854775807L |
328 | #define UINT64_MAX 18446744073709551615U |
324 | #define UINT64_MAX 18446744073709551615U |
329 | #elif __have_longlong64 |
325 | #elif __have_longlong64 |
330 | #define INT64_MIN (-9223372036854775807LL-1LL) |
326 | #define INT64_MIN (-9223372036854775807LL-1LL) |
331 | #define INT64_MAX 9223372036854775807LL |
327 | #define INT64_MAX 9223372036854775807LL |
332 | #define UINT64_MAX 18446744073709551615ULL |
328 | #define UINT64_MAX 18446744073709551615ULL |
333 | #endif |
329 | #endif |
334 | #endif |
330 | #endif |
335 | 331 | ||
336 | #if __int_least64_t_defined |
332 | #if __int_least64_t_defined |
337 | #if __have_long64 |
333 | #if __have_long64 |
338 | #define INT_LEAST64_MIN (-9223372036854775807L-1L) |
334 | #define INT_LEAST64_MIN (-9223372036854775807L-1L) |
339 | #define INT_LEAST64_MAX 9223372036854775807L |
335 | #define INT_LEAST64_MAX 9223372036854775807L |
340 | #define UINT_LEAST64_MAX 18446744073709551615U |
336 | #define UINT_LEAST64_MAX 18446744073709551615U |
341 | #elif __have_longlong64 |
337 | #elif __have_longlong64 |
342 | #define INT_LEAST64_MIN (-9223372036854775807LL-1LL) |
338 | #define INT_LEAST64_MIN (-9223372036854775807LL-1LL) |
343 | #define INT_LEAST64_MAX 9223372036854775807LL |
339 | #define INT_LEAST64_MAX 9223372036854775807LL |
344 | #define UINT_LEAST64_MAX 18446744073709551615ULL |
340 | #define UINT_LEAST64_MAX 18446744073709551615ULL |
345 | #endif |
341 | #endif |
346 | #endif |
342 | #endif |
347 | 343 | ||
348 | #if __int_fast8_t_defined |
344 | #if __int_fast8_t_defined |
349 | #if __STDINT_EXP(INT_MAX) >= 0x7f |
345 | #if __STDINT_EXP(INT_MAX) >= 0x7f |
350 | #define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX)-1) |
346 | #define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX)-1) |
351 | #define INT_FAST8_MAX __STDINT_EXP(INT_MAX) |
347 | #define INT_FAST8_MAX __STDINT_EXP(INT_MAX) |
352 | #define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX)*2U+1U) |
348 | #define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX)*2U+1U) |
353 | #else |
349 | #else |
354 | #define INT_FAST8_MIN INT_LEAST8_MIN |
350 | #define INT_FAST8_MIN INT_LEAST8_MIN |
355 | #define INT_FAST8_MAX INT_LEAST8_MAX |
351 | #define INT_FAST8_MAX INT_LEAST8_MAX |
356 | #define UINT_FAST8_MAX UINT_LEAST8_MAX |
352 | #define UINT_FAST8_MAX UINT_LEAST8_MAX |
357 | #endif |
353 | #endif |
358 | #endif |
354 | #endif |
359 | 355 | ||
360 | #if __int_fast16_t_defined |
356 | #if __int_fast16_t_defined |
361 | #if __STDINT_EXP(INT_MAX) >= 0x7fff |
357 | #if __STDINT_EXP(INT_MAX) >= 0x7fff |
362 | #define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX)-1) |
358 | #define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX)-1) |
363 | #define INT_FAST16_MAX __STDINT_EXP(INT_MAX) |
359 | #define INT_FAST16_MAX __STDINT_EXP(INT_MAX) |
364 | #define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX)*2U+1U) |
360 | #define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX)*2U+1U) |
365 | #else |
361 | #else |
366 | #define INT_FAST16_MIN INT_LEAST16_MIN |
362 | #define INT_FAST16_MIN INT_LEAST16_MIN |
367 | #define INT_FAST16_MAX INT_LEAST16_MAX |
363 | #define INT_FAST16_MAX INT_LEAST16_MAX |
368 | #define UINT_FAST16_MAX UINT_LEAST16_MAX |
364 | #define UINT_FAST16_MAX UINT_LEAST16_MAX |
369 | #endif |
365 | #endif |
370 | #endif |
366 | #endif |
371 | 367 | ||
372 | #if __int_fast32_t_defined |
368 | #if __int_fast32_t_defined |
373 | #if __STDINT_EXP(INT_MAX) >= 0x7fffffff |
369 | #if __STDINT_EXP(INT_MAX) >= 0x7fffffff |
374 | #define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX)-1) |
370 | #define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX)-1) |
375 | #define INT_FAST32_MAX __STDINT_EXP(INT_MAX) |
371 | #define INT_FAST32_MAX __STDINT_EXP(INT_MAX) |
376 | #define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX)*2U+1U) |
372 | #define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX)*2U+1U) |
377 | #else |
373 | #else |
378 | #define INT_FAST32_MIN INT_LEAST32_MIN |
374 | #define INT_FAST32_MIN INT_LEAST32_MIN |
379 | #define INT_FAST32_MAX INT_LEAST32_MAX |
375 | #define INT_FAST32_MAX INT_LEAST32_MAX |
380 | #define UINT_FAST32_MAX UINT_LEAST32_MAX |
376 | #define UINT_FAST32_MAX UINT_LEAST32_MAX |
381 | #endif |
377 | #endif |
382 | #endif |
378 | #endif |
383 | 379 | ||
384 | #if __int_fast64_t_defined |
380 | #if __int_fast64_t_defined |
385 | #if __STDINT_EXP(INT_MAX) > 0x7fffffff |
381 | #if __STDINT_EXP(INT_MAX) > 0x7fffffff |
386 | #define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX)-1) |
382 | #define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX)-1) |
387 | #define INT_FAST64_MAX __STDINT_EXP(INT_MAX) |
383 | #define INT_FAST64_MAX __STDINT_EXP(INT_MAX) |
388 | #define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX)*2U+1U) |
384 | #define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX)*2U+1U) |
389 | #else |
385 | #else |
390 | #define INT_FAST64_MIN INT_LEAST64_MIN |
386 | #define INT_FAST64_MIN INT_LEAST64_MIN |
391 | #define INT_FAST64_MAX INT_LEAST64_MAX |
387 | #define INT_FAST64_MAX INT_LEAST64_MAX |
392 | #define UINT_FAST64_MAX UINT_LEAST64_MAX |
388 | #define UINT_FAST64_MAX UINT_LEAST64_MAX |
393 | #endif |
389 | #endif |
394 | #endif |
390 | #endif |
395 | 391 | ||
396 | #ifdef __INTMAX_MAX__ |
392 | #ifdef __INTMAX_MAX__ |
397 | #define INTMAX_MAX __INTMAX_MAX__ |
393 | #define INTMAX_MAX __INTMAX_MAX__ |
398 | #define INTMAX_MIN (-INTMAX_MAX - 1) |
394 | #define INTMAX_MIN (-INTMAX_MAX - 1) |
399 | #elif defined(__INTMAX_TYPE__) |
395 | #elif defined(__INTMAX_TYPE__) |
400 | /* All relevant GCC versions prefer long to long long for intmax_t. */ |
396 | /* All relevant GCC versions prefer long to long long for intmax_t. */ |
401 | #define INTMAX_MAX INT64_MAX |
397 | #define INTMAX_MAX INT64_MAX |
402 | #define INTMAX_MIN INT64_MIN |
398 | #define INTMAX_MIN INT64_MIN |
403 | #endif |
399 | #endif |
404 | 400 | ||
405 | #ifdef __UINTMAX_MAX__ |
401 | #ifdef __UINTMAX_MAX__ |
406 | #define UINTMAX_MAX __UINTMAX_MAX__ |
402 | #define UINTMAX_MAX __UINTMAX_MAX__ |
407 | #elif defined(__UINTMAX_TYPE__) |
403 | #elif defined(__UINTMAX_TYPE__) |
408 | /* All relevant GCC versions prefer long to long long for intmax_t. */ |
404 | /* All relevant GCC versions prefer long to long long for intmax_t. */ |
409 | #define UINTMAX_MAX UINT64_MAX |
405 | #define UINTMAX_MAX UINT64_MAX |
410 | #endif |
406 | #endif |
411 | 407 | ||
412 | /* This must match size_t in stddef.h, currently long unsigned int */ |
408 | /* This must match size_t in stddef.h, currently long unsigned int */ |
413 | #ifdef __SIZE_MAX__ |
409 | #ifdef __SIZE_MAX__ |
414 | #define SIZE_MAX __SIZE_MAX__ |
410 | #define SIZE_MAX __SIZE_MAX__ |
415 | #else |
411 | #else |
416 | #define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) |
412 | #define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) |
417 | #endif |
413 | #endif |
418 | 414 | ||
419 | /* This must match sig_atomic_t in |
415 | /* This must match sig_atomic_t in |
420 | #define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1) |
416 | #define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1) |
421 | #define SIG_ATOMIC_MAX __STDINT_EXP(INT_MAX) |
417 | #define SIG_ATOMIC_MAX __STDINT_EXP(INT_MAX) |
422 | 418 | ||
423 | /* This must match ptrdiff_t in |
419 | /* This must match ptrdiff_t in |
424 | #ifdef __PTRDIFF_MAX__ |
420 | #ifdef __PTRDIFF_MAX__ |
425 | #define PTRDIFF_MAX __PTRDIFF_MAX__ |
421 | #define PTRDIFF_MAX __PTRDIFF_MAX__ |
426 | #else |
422 | #else |
427 | #define PTRDIFF_MAX __STDINT_EXP(LONG_MAX) |
423 | #define PTRDIFF_MAX __STDINT_EXP(LONG_MAX) |
428 | #endif |
424 | #endif |
429 | #define PTRDIFF_MIN (-PTRDIFF_MAX - 1) |
425 | #define PTRDIFF_MIN (-PTRDIFF_MAX - 1) |
430 | 426 | ||
431 | #ifdef __WCHAR_MAX__ |
427 | #ifdef __WCHAR_MAX__ |
432 | #define WCHAR_MAX __WCHAR_MAX__ |
428 | #define WCHAR_MAX __WCHAR_MAX__ |
433 | #endif |
429 | #endif |
434 | #ifdef __WCHAR_MIN__ |
430 | #ifdef __WCHAR_MIN__ |
435 | #define WCHAR_MIN __WCHAR_MIN__ |
431 | #define WCHAR_MIN __WCHAR_MIN__ |
436 | #endif |
432 | #endif |
437 | 433 | ||
438 | /* wint_t is unsigned int on almost all GCC targets. */ |
434 | /* wint_t is unsigned int on almost all GCC targets. */ |
439 | #ifdef __WINT_MAX__ |
435 | #ifdef __WINT_MAX__ |
440 | #define WINT_MAX __WINT_MAX__ |
436 | #define WINT_MAX __WINT_MAX__ |
441 | #else |
437 | #else |
442 | #define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) |
438 | #define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) |
443 | #endif |
439 | #endif |
444 | #ifdef __WINT_MIN__ |
440 | #ifdef __WINT_MIN__ |
445 | #define WINT_MIN __WINT_MIN__ |
441 | #define WINT_MIN __WINT_MIN__ |
446 | #else |
442 | #else |
447 | #define WINT_MIN 0U |
443 | #define WINT_MIN 0U |
448 | #endif |
444 | #endif |
449 | 445 | ||
450 | /** Macros for minimum-width integer constant expressions */ |
446 | /** Macros for minimum-width integer constant expressions */ |
451 | #define INT8_C(x) x |
447 | #define INT8_C(x) x |
452 | #if __STDINT_EXP(INT_MAX) > 0x7f |
448 | #if __STDINT_EXP(INT_MAX) > 0x7f |
453 | #define UINT8_C(x) x |
449 | #define UINT8_C(x) x |
454 | #else |
450 | #else |
455 | #define UINT8_C(x) x##U |
451 | #define UINT8_C(x) x##U |
456 | #endif |
452 | #endif |
457 | 453 | ||
458 | #define INT16_C(x) x |
454 | #define INT16_C(x) x |
459 | #if __STDINT_EXP(INT_MAX) > 0x7fff |
455 | #if __STDINT_EXP(INT_MAX) > 0x7fff |
460 | #define UINT16_C(x) x |
456 | #define UINT16_C(x) x |
461 | #else |
457 | #else |
462 | #define UINT16_C(x) x##U |
458 | #define UINT16_C(x) x##U |
463 | #endif |
459 | #endif |
464 | 460 | ||
465 | #if __have_long32 |
461 | #if __have_long32 |
466 | #define INT32_C(x) x##L |
462 | #define INT32_C(x) x##L |
467 | #define UINT32_C(x) x##UL |
463 | #define UINT32_C(x) x##UL |
468 | #else |
464 | #else |
469 | #define INT32_C(x) x |
465 | #define INT32_C(x) x |
470 | #define UINT32_C(x) x##U |
466 | #define UINT32_C(x) x##U |
471 | #endif |
467 | #endif |
472 | 468 | ||
473 | #if __int64_t_defined |
469 | #if __int64_t_defined |
474 | #if __have_long64 |
470 | #if __have_long64 |
475 | #define INT64_C(x) x##L |
471 | #define INT64_C(x) x##L |
476 | #define UINT64_C(x) x##UL |
472 | #define UINT64_C(x) x##UL |
477 | #else |
473 | #else |
478 | #define INT64_C(x) x##LL |
474 | #define INT64_C(x) x##LL |
479 | #define UINT64_C(x) x##ULL |
475 | #define UINT64_C(x) x##ULL |
480 | #endif |
476 | #endif |
481 | #endif |
477 | #endif |
482 | 478 | ||
483 | /** Macros for greatest-width integer constant expression */ |
479 | /** Macros for greatest-width integer constant expression */ |
484 | #if __have_long64 |
480 | #if __have_long64 |
485 | #define INTMAX_C(x) x##L |
481 | #define INTMAX_C(x) x##L |
486 | #define UINTMAX_C(x) x##UL |
482 | #define UINTMAX_C(x) x##UL |
487 | #else |
483 | #else |
488 | #define INTMAX_C(x) x##LL |
484 | #define INTMAX_C(x) x##LL |
489 | #define UINTMAX_C(x) x##ULL |
485 | #define UINTMAX_C(x) x##ULL |
490 | #endif |
486 | #endif |
491 | 487 | ||
492 | 488 | ||
493 | #ifdef __cplusplus |
489 | #ifdef __cplusplus |
494 | } |
490 | } |
495 | #endif |
491 | #endif |
496 | 492 | ||
497 | #endif /* _STDINT_H */ |
493 | #endif /* _STDINT_H */ |