]> sourceware.org Git - newlib-cygwin.git/blame - newlib/libc/include/stdint.h
* include/sys/time.h: Move more cygwin stuff to cygwin-specific header.
[newlib-cygwin.git] / newlib / libc / include / stdint.h
CommitLineData
df5a5b35
JJ
1/*
2 * Copyright (c) 2004, 2005 by
3 * Ralf Corsepius, Ulm/Germany. All rights reserved.
4 *
5 * Permission to use, copy, modify, and distribute this software
6 * is freely granted, provided that this notice is preserved.
7 */
8
9/*
df5a5b35
JJ
10 * @todo - Add support for wint_t types.
11 */
12
13#ifndef _STDINT_H
14#define _STDINT_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
ee694aea
JJ
20#if defined(__GNUC__) && \
21 ( (__GNUC__ >= 4) || \
22 ( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2) ) )
23/* gcc > 3.2 implicitly defines the values we are interested */
0ce4fcef 24#define __STDINT_EXP(x) __##x##__
df5a5b35 25#else
0ce4fcef 26#define __STDINT_EXP(x) x
df5a5b35
JJ
27#include <limits.h>
28#endif
29
c7e20979
JJ
30/* Check if "long long" is 64bit wide */
31/* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */
32#if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \
33 || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) )
34#define __have_longlong64 1
35#endif
36
37/* Check if "long" is 64bit or 32bit wide */
38#if __STDINT_EXP(LONG_MAX) > 0x7fffffff
39#define __have_long64 1
40#elif __STDINT_EXP(LONG_MAX) == 0x7fffffff
41#define __have_long32 1
42#endif
43
0ce4fcef 44#if __STDINT_EXP(SCHAR_MAX) == 0x7f
df5a5b35
JJ
45typedef signed char int8_t ;
46typedef unsigned char uint8_t ;
47#define __int8_t_defined 1
48#endif
49
50#if __int8_t_defined
51typedef signed char int_least8_t;
52typedef unsigned char uint_least8_t;
53#define __int_least8_t_defined 1
54#endif
55
0ce4fcef 56#if __STDINT_EXP(SHRT_MAX) == 0x7fff
df5a5b35
JJ
57typedef signed short int16_t;
58typedef unsigned short uint16_t;
59#define __int16_t_defined 1
0ce4fcef 60#elif __STDINT_EXP(INT_MAX) == 0x7fff
df5a5b35
JJ
61typedef signed int int16_t;
62typedef unsigned int uint16_t;
63#define __int16_t_defined 1
0ce4fcef 64#elif __STDINT_EXP(SCHAR_MAX) == 0x7fff
df5a5b35
JJ
65typedef signed char int16_t;
66typedef unsigned char uint16_t;
67#define __int16_t_defined 1
68#endif
69
70#if __int16_t_defined
71typedef int16_t int_least16_t;
72typedef uint16_t uint_least16_t;
73#define __int_least16_t_defined 1
74
71ac53ee 75#if !__int_least8_t_defined
df5a5b35
JJ
76typedef int16_t int_least8_t;
77typedef uint16_t uint_least8_t;
78#define __int_least8_t_defined 1
79#endif
80#endif
81
0ce4fcef 82#if __STDINT_EXP(INT_MAX) == 0x7fffffffL
df5a5b35
JJ
83typedef signed int int32_t;
84typedef unsigned int uint32_t;
85#define __int32_t_defined 1
0ce4fcef 86#elif __STDINT_EXP(LONG_MAX) == 0x7fffffffL
df5a5b35
JJ
87typedef signed long int32_t;
88typedef unsigned long uint32_t;
89#define __int32_t_defined 1
0ce4fcef 90#elif __STDINT_EXP(SHRT_MAX) == 0x7fffffffL
df5a5b35
JJ
91typedef signed short int32_t;
92typedef unsigned short uint32_t;
93#define __int32_t_defined 1
0ce4fcef 94#elif __STDINT_EXP(SCHAR_MAX) == 0x7fffffffL
df5a5b35
JJ
95typedef signed char int32_t;
96typedef unsigned char uint32_t;
97#define __int32_t_defined 1
98#endif
99
100#if __int32_t_defined
101typedef int32_t int_least32_t;
102typedef uint32_t uint_least32_t;
103#define __int_least32_t_defined 1
104
71ac53ee 105#if !__int_least8_t_defined
df5a5b35
JJ
106typedef int32_t int_least8_t;
107typedef uint32_t uint_least8_t;
108#define __int_least8_t_defined 1
109#endif
110
71ac53ee 111#if !__int_least16_t_defined
df5a5b35
JJ
112typedef int32_t int_least16_t;
113typedef uint32_t uint_least16_t;
114#define __int_least16_t_defined 1
115#endif
116#endif
117
c7e20979 118#if __have_long64
df5a5b35
JJ
119typedef signed long int64_t;
120typedef unsigned long uint64_t;
121#define __int64_t_defined 1
c7e20979 122#elif __have_longlong64
df5a5b35
JJ
123typedef signed long long int64_t;
124typedef unsigned long long uint64_t;
125#define __int64_t_defined 1
0ce4fcef 126#elif __STDINT_EXP(INT_MAX) > 0x7fffffff
df5a5b35
JJ
127typedef signed int int64_t;
128typedef unsigned int uint64_t;
129#define __int64_t_defined 1
130#endif
131
132#if __int64_t_defined
133typedef int64_t int_least64_t;
134typedef uint64_t uint_least64_t;
135#define __int_least64_t_defined 1
136
71ac53ee 137#if !__int_least8_t_defined
df5a5b35
JJ
138typedef int64_t int_least8_t;
139typedef uint64_t uint_least8_t;
140#define __int_least8_t_defined 1
141#endif
142
71ac53ee 143#if !__int_least16_t_defined
df5a5b35
JJ
144typedef int64_t int_least16_t;
145typedef uint64_t uint_least16_t;
146#define __int_least16_t_defined 1
147#endif
148
71ac53ee 149#if !__int_least32_t_defined
df5a5b35
JJ
150typedef int64_t int_least32_t;
151typedef uint64_t uint_least32_t;
152#define __int_least32_t_defined 1
153#endif
154#endif
155
bc037f3a
JJ
156/*
157 * Fastest minimum-width integer types
158 *
159 * Assume int to be the fastest type for all types with a width
160 * less than __INT_MAX__ rsp. INT_MAX
161 */
162#if __STDINT_EXP(INT_MAX) >= 0x7f
163 typedef signed int int_fast8_t;
164 typedef unsigned int uint_fast8_t;
165#define __int_fast8_t_defined 1
166#endif
167
168#if __STDINT_EXP(INT_MAX) >= 0x7fff
169 typedef signed int int_fast16_t;
170 typedef unsigned int uint_fast16_t;
171#define __int_fast16_t_defined 1
172#endif
173
174#if __STDINT_EXP(INT_MAX) >= 0x7fffffff
175 typedef signed int int_fast32_t;
176 typedef unsigned int uint_fast32_t;
177#define __int_fast32_t_defined 1
178#endif
179
180#if __STDINT_EXP(INT_MAX) > 0x7fffffff
181 typedef signed int int_fast64_t;
182 typedef unsigned int uint_fast64_t;
183#define __int_fast64_t_defined 1
184#endif
185
186/*
187 * Fall back to [u]int_least<N>_t for [u]int_fast<N>_t types
188 * not having been defined, yet.
189 * Leave undefined, if [u]int_least<N>_t should not be available.
190 */
191#if !__int_fast8_t_defined
192#if __int_least8_t_defined
193 typedef int_least8_t int_fast8_t;
194 typedef uint_least8_t uint_fast8_t;
195#define __int_fast8_t_defined 1
196#endif
197#endif
198
199#if !__int_fast16_t_defined
200#if __int_least16_t_defined
201 typedef int_least16_t int_fast16_t;
202 typedef uint_least16_t uint_fast16_t;
203#define __int_fast16_t_defined 1
204#endif
205#endif
206
207#if !__int_fast32_t_defined
208#if __int_least32_t_defined
209 typedef int_least32_t int_fast32_t;
210 typedef uint_least32_t uint_fast32_t;
211#define __int_fast32_t_defined 1
212#endif
213#endif
214
215#if !__int_fast64_t_defined
216#if __int_least64_t_defined
217 typedef int_least64_t int_fast64_t;
218 typedef uint_least64_t uint_fast64_t;
219#define __int_fast64_t_defined 1
220#endif
221#endif
222
14491fd0
JJ
223/* Greatest-width integer types */
224/* Modern GCCs provide __INTMAX_TYPE__ */
225#if defined(__INTMAX_TYPE__)
226 typedef __INTMAX_TYPE__ intmax_t;
227#elif __have_longlong64
228 typedef signed long long intmax_t;
df5a5b35 229#else
14491fd0 230 typedef signed long intmax_t;
df5a5b35
JJ
231#endif
232
14491fd0
JJ
233/* Modern GCCs provide __UINTMAX_TYPE__ */
234#if defined(__UINTMAX_TYPE__)
235 typedef __UINTMAX_TYPE__ uintmax_t;
236#elif __have_longlong64
237 typedef unsigned long long uintmax_t;
c7e20979 238#else
14491fd0 239 typedef unsigned long uintmax_t;
c7e20979 240#endif
14491fd0 241
df5a5b35 242/*
14491fd0 243 * GCC doesn't provide an appropriate macro for [u]intptr_t
df5a5b35
JJ
244 * For now, use __PTRDIFF_TYPE__
245 */
246#if defined(__PTRDIFF_TYPE__)
247typedef signed __PTRDIFF_TYPE__ intptr_t;
248typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
249#else
250/*
251 * Fallback to hardcoded values,
252 * should be valid on cpu's with 32bit int/32bit void*
253 */
254typedef signed long intptr_t;
255typedef unsigned long uintptr_t;
256#endif
257
258/* Limits of Specified-Width Integer Types */
259
260#if __int8_t_defined
261#define INT8_MIN -128
262#define INT8_MAX 127
263#define UINT8_MAX 255
264#endif
265
266#if __int_least8_t_defined
17060817
JJ
267#define INT_LEAST8_MIN -128
268#define INT_LEAST8_MAX 127
269#define UINT_LEAST8_MAX 255
df5a5b35
JJ
270#else
271#error required type int_least8_t missing
272#endif
273
274#if __int16_t_defined
275#define INT16_MIN -32768
276#define INT16_MAX 32767
277#define UINT16_MAX 65535
278#endif
279
280#if __int_least16_t_defined
17060817
JJ
281#define INT_LEAST16_MIN -32768
282#define INT_LEAST16_MAX 32767
283#define UINT_LEAST16_MAX 65535
df5a5b35
JJ
284#else
285#error required type int_least16_t missing
286#endif
287
288#if __int32_t_defined
0ce4fcef 289#define INT32_MIN (-2147483647-1)
df5a5b35 290#define INT32_MAX 2147483647
0ce4fcef 291#define UINT32_MAX 4294967295U
df5a5b35
JJ
292#endif
293
294#if __int_least32_t_defined
0ce4fcef 295#define INT_LEAST32_MIN (-2147483647-1)
17060817 296#define INT_LEAST32_MAX 2147483647
0ce4fcef 297#define UINT_LEAST32_MAX 4294967295U
df5a5b35
JJ
298#else
299#error required type int_least32_t missing
300#endif
301
302#if __int64_t_defined
71ac53ee 303#if __have_long64
0ce4fcef
JJ
304#define INT64_MIN (-9223372036854775807L-1L)
305#define INT64_MAX 9223372036854775807L
306#define UINT64_MAX 18446744073709551615U
c7e20979 307#elif __have_longlong64
0ce4fcef
JJ
308#define INT64_MIN (-9223372036854775807LL-1LL)
309#define INT64_MAX 9223372036854775807LL
310#define UINT64_MAX 18446744073709551615ULL
311#endif
df5a5b35
JJ
312#endif
313
314#if __int_least64_t_defined
71ac53ee 315#if __have_long64
0ce4fcef
JJ
316#define INT_LEAST64_MIN (-9223372036854775807L-1L)
317#define INT_LEAST64_MAX 9223372036854775807L
318#define UINT_LEAST64_MAX 18446744073709551615U
c7e20979 319#elif __have_longlong64
0ce4fcef
JJ
320#define INT_LEAST64_MIN (-9223372036854775807LL-1LL)
321#define INT_LEAST64_MAX 9223372036854775807LL
322#define UINT_LEAST64_MAX 18446744073709551615ULL
323#endif
df5a5b35
JJ
324#endif
325
bc037f3a
JJ
326#if __int_fast8_t_defined
327#define INT_FAST8_MIN INT8_MIN
328#define INT_FAST8_MAX INT8_MAX
329#define UINT_FAST8_MAX UINT8_MAX
330#endif
331
332#if __int_fast16_t_defined
333#define INT_FAST16_MIN INT16_MIN
334#define INT_FAST16_MAX INT16_MAX
335#define UINT_FAST16_MAX UINT16_MAX
336#endif
337
338#if __int_fast32_t_defined
339#define INT_FAST32_MIN INT32_MIN
340#define INT_FAST32_MAX INT32_MAX
341#define UINT_FAST32_MAX UINT32_MAX
342#endif
343
344#if __int_fast64_t_defined
345#define INT_FAST64_MIN INT64_MIN
346#define INT_FAST64_MAX INT64_MAX
347#define UINT_FAST64_MAX UINT64_MAX
348#endif
349
df5a5b35 350/* This must match size_t in stddef.h, currently long unsigned int */
0ce4fcef
JJ
351#define SIZE_MIN (-__STDINT_EXP(LONG_MAX) - 1L)
352#define SIZE_MAX __STDINT_EXP(LONG_MAX)
df5a5b35
JJ
353
354/* This must match sig_atomic_t in <signal.h> (currently int) */
0ce4fcef
JJ
355#define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1)
356#define SIG_ATOMIC_MAX __STDINT_EXP(INT_MAX)
df5a5b35
JJ
357
358/* This must match ptrdiff_t in <stddef.h> (currently long int) */
0ce4fcef
JJ
359#define PTRDIFF_MIN (-__STDINT_EXP(LONG_MAX) - 1L)
360#define PTRDIFF_MAX __STDINT_EXP(LONG_MAX)
df5a5b35
JJ
361
362/** Macros for minimum-width integer constant expressions */
363#define INT8_C(x) x
364#define UINT8_C(x) x##U
365
366#define INT16_C(x) x
367#define UINT16_C(x) x##U
368
369#if __have_long32
370#define INT32_C(x) x##L
371#define UINT32_C(x) x##UL
372#else
373#define INT32_C(x) x
374#define UINT32_C(x) x##U
375#endif
376
377#if __int64_t_defined
378#if __have_longlong64
379#define INT64_C(x) x##LL
380#define UINT64_C(x) x##ULL
381#else
382#define INT64_C(x) x##L
383#define UINT64_C(x) x##UL
384#endif
385#endif
386
387/** Macros for greatest-width integer constant expression */
388#if __have_longlong64
389#define INTMAX_C(x) x##LL
390#define UINTMAX_C(x) x##ULL
391#else
392#define INTMAX_C(x) x##L
393#define UINTMAX_C(x) x##UL
394#endif
395
396
397#ifdef __cplusplus
398}
399#endif
400
401#endif /* _STDINT_H */
This page took 0.072478 seconds and 5 git commands to generate.