Subversion Repositories Kolibri OS

Rev

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