aboutsummaryrefslogtreecommitdiffstats
path: root/include/stdint.h
blob: 038521f7993c9a67e65adc77a5fe7ce165dcf10c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/**
 * slibc — Yet another C library
 * Copyright © 2015  Mattias Andrée (maandree@member.fsf.org)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _STDINT_H
#define _STDINT_H
#include <slibc/version.h>
#include <slibc/features.h>



#if defined(__C99__)
# define __NEED_intN_t
# define __NEED_uintN_t
# define __NEED_int_leastN_t
# define __NEED_uint_leastN_t
# define __NEED_int_fastN_t
# define __NEED_uint_fastN_t
# define __NEED_intptr_t
# define __NEED_uintptr_t
# define __NEED_intmax_t
# define __NEED_uintmax_t
#endif
#include <bits/types.h>



#if defined(__C99__)
/**
 * Macro that ensure that a signed numeral literal
 * of at most 8 encoding bits does not overflow.
 */
# define  INT8_C(value)   value

/**
 * Macro that ensure that an unsigned numeral literal
 * of at most 8 encoding bits does not overflow.
 */
# define  UINT8_C(value)  value


/**
 * Macro that ensure that a signed numeral literal
 * of at most 16 encoding bits does not overflow.
 */
# define  INT16_C(value)   value

/**
 * Macro that ensure that an unsigned numeral literal
 * of at most 16 encoding bits does not overflow.
 */
# define  UINT16_C(value)  value ## U


/**
 * Macro that ensure that a signed numeral literal
 * of at most 32 encoding bits does not overflow.
 */
# if __INT_BIT == 16
#  define  INT32_C(value)   value ## L
# else
#  define  INT32_C(value)   value
# endif

/**
 * Macro that ensure that an unsigned numeral literal
 * of at most 32 encoding bits does not overflow.
 */
# if __INT_BIT == 16
#  define  UINT32_C(value)  value ## UL
# else
#  define  UINT32_C(value)  value ## U
# endif


/**
 * Macro that ensure that a signed numeral literal
 * of at most 64 encoding bits does not overflow.
 */
# if __LONG_BIT == 32
#  define  INT64_C(value)   value ## LL
# else
#  define  INT64_C(value)   value ## L
# endif

/**
 * Macro that ensure that an unsigned numeral literal
 * of at most 64 encoding bits does not overflow.
 */
# if __LONG_BIT == 32
#  define  UINT64_C(value)  value ## ULL
# else
#  define  UINT64_C(value)  value ## UL
# endif


/**
 * Macro that ensure that any signed numeral literal
 * does not overflow, unless there is no scalar integer
 * type that can hold it.
 */
# if __LONG_BIT == __LONG_LONG_BIT
#  define  INTMAX_C(value)   value ## L
# else
#  define  INTMAX_C(value)   value ## LL
# endif

/**
 * Macro that ensure that any unsigned numeral literal
 * does not overflow, unless there is no scalar integer
 * type that can hold it.
 */
# if __LONG_BIT == __LONG_LONG_BIT
#  define  UINTMAX_C(value)   value ## UL
# else
#  define  UINTMAX_C(value)   value ## ULL
# endif



/**
 * Maximum value of `uint8_t`.
 */
# define UINT8_MAX  (UINT8_C(0xFF))

/**
 * Maximum value of `int8_t`.
 */
# define INT8_MAX  (INT8_C(0x7F))

/**
 * Minimum value of `int8_t`.
 */
# define INT8_MIN  (-(INT8_MAX) - 1)


/**
 * Maximum value of `uint16_t`.
 */
# define UINT16_MAX  (UINT16_C(0xFFFF))

/**
 * Maximum value of `int16_t`.
 */
# define INT16_MAX  (INT16_C(0x7FFF))

/**
 * Minimum value of `int16_t`.
 */
# define INT16_MIN  (-(INT16_MAX) - 1)


/**
 * Maximum value of `uint32_t`.
 */
# define UINT32_MAX  (UINT32_C(0xFFFFFFFF))

/**
 * Maximum value of `int32_t`.
 */
# define INT32_MAX  (INT32_C(0x7FFFFFFF))

/**
 * Minimum value of `int32_t`.
 */
# define INT32_MIN  (-(INT32_MAX) - 1)


/**
 * Maximum value of `uint64_t`.
 */
# define UINT64_MAX  (UINT64_C(0xFFFFFFFFFFFFFFFF))

/**
 * Maximum value of `int64_t`.
 */
# define INT64_MAX  (INT64_C(0x7FFFFFFFFFFFFFFF))

/**
 * Minimum value of `int64_t`.
 */
# define INT64_MIN  (-(INT64_MAX) - 1)


/**
 * Maximum value of `uint_least8_t`.
 */
# define UINT_LEAST8_MAX  UINT8_MAX

/**
 * Maximum value of `int_least8_t`.
 */
# define INT_LEAST8_MAX  INT8_MAX

/**
 * Minimum value of `int_least8_t`.
 */
# define INT_LEAST8_MIN  (__MAX_TO_MIN(INT_LEAST8_MAX))


/**
 * Maximum value of `uint_least16_t`.
 */
# define UINT_LEAST16_MAX  UINT16_MAX

/**
 * Maximum value of `int_least16_t`.
 */
# define INT_LEAST16_MAX  INT16_MAX

/**
 * Minimum value of `int_least16_t`.
 */
# define INT_LEAST16_MIN  (__MAX_TO_MIN(INT_LEAST16_MAX))


/**
 * Maximum value of `uint_least32_t`.
 */
# define UINT_LEAST32_MAX  UINT32_MAX

/**
 * Maximum value of `int_least32_t`.
 */
# define INT_LEAST32_MAX  INT32_MAX

/**
 * Minimum value of `int_least32_t`.
 */
# define INT_LEAST32_MIN  (__MAX_TO_MIN(INT_LEAST32_MAX))


/**
 * Maximum value of `uint_least64_t`.
 */
# define UINT_LEAST64_MAX  UINT64_MAX

/**
 * Maximum value of `int_least64_t`.
 */
# define INT_LEAST64_MAX  INT64_MAX

/**
 * Minimum value of `int_least64_t`.
 */
# define INT_LEAST64_MIN  (__MAX_TO_MIN(INT_LEAST64_MAX))


/**
 * Maximum value of `uint_fast8_t`.
 */
# define UINT_FAST8_MAX  __UINT_FAST8_MAX

/**
 * Maximum value of `int_fast8_t`.
 */
# define INT_FAST8_MAX  __INT_FAST8_MAX

/**
 * Minimum value of `int_fast8_t`.
 */
# define INT_FAST8_MIN  (__MAX_TO_MIN(INT_FAST8_MAX))


/**
 * Maximum value of `uint_fast16_t`.
 */
# define UINT_FAST16_MAX  __UINT_FAST16_MAX

/**
 * Maximum value of `int_fast16_t`.
 */
# define INT_FAST16_MAX  __INT_FAST16_MAX

/**
 * Minimum value of `int_fast16_t`.
 */
# define INT_FAST16_MIN  (__MAX_TO_MIN(INT_FAST16_MAX))


/**
 * Maximum value of `uint_fast32_t`.
 */
# define UINT_FAST32_MAX  __UINT_FAST32_MAX

/**
 * Maximum value of `int_fast32_t`.
 */
# define INT_FAST32_MAX  __INT_FAST32_MAX

/**
 * Minimum value of `int_fast32_t`.
 */
# define INT_FAST32_MIN  (__MAX_TO_MIN(INT_FAST32_MAX))


/**
 * Maximum value of `uint_fast64_t`.
 */
# define UINT_FAST64_MAX  __UINT_FAST64_MAX

/**
 * Maximum value of `int_fast64_t`.
 */
# define INT_FAST64_MAX  __INT_FAST64_MAX

/**
 * Minimum value of `int_fast64_t`.
 */
# define INT_FAST64_MIN  (__MAX_TO_MIN(INT_FAST64_MAX))


/**
 * Maximum value of `uintmax_t`.
 */
# define UINTMAX_MAX  __UINTMAX_MAX

/**
 * Maximum value of `intmax_t`.
 */
# define INTMAX_MAX  __INTMAX_MAX

/**
 * Minimum value of `intmax_t`.
 */
# define INTMAX_MIN  (__MAX_TO_MIN(INTMAX_MIN))


/**
 * Maximum value of `uintptr_t`.
 */
# if __PTR_BIT == 8
#  define UINTPTR_MAX  UINT8_MAX
# elif __PTR_BIT == 16
#  define UINTPTR_MAX  UINT16_MAX
# elif __PTR_BIT == 32
#  define UINTPTR_MAX  UINT32_MAX
# else
#  define UINTPTR_MAX  UINT64_MAX
# endif

/**
 * Maximum value of `intptr_t`.
 */
# if __PTR_BIT == 8
#  define INTPTR_MAX  INT8_MAX
# elif __PTR_BIT == 16
#  define INTPTR_MAX  INT16_MAX
# elif __PTR_BIT == 32
#  define INTPTR_MAX  INT32_MAX
# else
#  define INTPTR_MAX  INT64_MAX
# endif

/**
 * Minimum value of `intptr_t`.
 */
# define INTPTR_MIN  (__MAX_TO_MIN(INTPTR_MAX))
#endif


/**
 * Maximum value of `size_t`.
 */
#define SIZE_MAX  UINTPTR_MAX

/**
 * Maximum value of `ssize_t`.
 */
#define SSIZE_MAX  INTPTR_MAX

/**
 * Minimum value of `ssize_t`.
 */
#define SSIZE_MIN  INTPTR_MIN


#ifndef __PORTABLE
/**
 * Maximum value of `wchar_t`.
 */
# define WCHAR_MAX  __WCHAR_MAX

/**
 * Minimum value of `wchar_t`.
 */
# define WCHAR_MIN  (__MAX_TO_MIN(WCHAR_MAX))


/**
 * Maximum value of `wint_t`.
 */
# define WINT_MAX  WCHAR_MAX

/**
 * Minimum value of `wint_t`.
 */
# define WINT_MIN  WCHAR_MIN
#endif


/**
 * Maximum value of `sig_atomic_t`.
 */
#if __SIG_ATOMIC_BIT == 8
# define SIG_ATOMIC_MAX  INT8_MAX
#elif __SIG_ATOMIC_BIT == 16
# define SIG_ATOMIC_MAX  INT16_MAX
#elif __SIG_ATOMIC_BIT == 32
# define SIG_ATOMIC_MAX  INT32_MAX
#else
# define SIG_ATOMIC_MAX  INT64_MAX
#endif

/**
 * Minimum value of `sig_atomic_t`.
 */
#define SIG_ATOMIC_MIN  (__MAX_TO_MIN(__SIG_ATOMIC_MAX))



#endif