Subversion Repositories Kolibri OS

Rev

Rev 4921 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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