The OpenD Programming Language

1 /**
2  * D header file for C99.
3  *
4  * $(C_HEADER_DESCRIPTION pubs.opengroup.org/onlinepubs/009695399/basedefs/_stdint.h.html, _stdint.h)
5  *
6  * Copyright: Copyright Sean Kelly 2005 - 2018
7  * License: Distributed under the
8  *      $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
9  *    (See accompanying file LICENSE)
10  * Authors:   Sean Kelly
11  * Source:    $(DRUNTIMESRC core/stdc/_stdint.d)
12  * Standards: ISO/IEC 9899:1999 (E)
13  */
14 
15 module core.stdc.stdint;
16 
17 import core.stdc.config;
18 import core.stdc.stddef; // for wchar_t
19 import core.stdc.signal; // for sig_atomic_t
20 import core.stdc.wchar_; // for wint_t
21 
22 version (OSX)
23     version = Darwin;
24 else version (iOS)
25     version = Darwin;
26 else version (TVOS)
27     version = Darwin;
28 else version (WatchOS)
29     version = Darwin;
30 
31 // Can't be `private` because of @@@BUG11173@@@.
32 T _typify(T)(T val) @safe pure nothrow { return val; }
33 
34 extern (C):
35 @trusted: // Types and constants only.
36 nothrow:
37 @nogc:
38 
39 
40 static if (is(ucent))
41 {
42     alias int128_t = cent;   ///
43     alias uint128_t = ucent; ///
44 }
45 
46 version (Windows)
47 {
48     alias int8_t   = byte;   ///
49     alias int16_t  = short;  ///
50     alias uint8_t  = ubyte;  ///
51     alias uint16_t = ushort; ///
52     version (CRuntime_DigitalMars)
53     {
54         alias int32_t  = cpp_long;  ///
55         alias uint32_t = cpp_ulong; ///
56     }
57     else
58     {
59         alias int32_t  = int;  ///
60         alias uint32_t = uint; ///
61     }
62     alias int64_t  = long;   ///
63     alias uint64_t = ulong;  ///
64 
65     alias int_least8_t   = byte;     ///
66     alias uint_least8_t  = ubyte;    ///
67     alias int_least16_t  = short;    ///
68     alias uint_least16_t = ushort;   ///
69     alias int_least32_t  = int32_t;  ///
70     alias uint_least32_t = uint32_t; ///
71     alias int_least64_t  = long;     ///
72     alias uint_least64_t = ulong;    ///
73 
74     alias int_fast8_t   = byte;     ///
75     alias uint_fast8_t  = ubyte;    ///
76     version (MinGW)
77     {
78         alias int_fast16_t  = short;  ///
79         alias uint_fast16_t = ushort; ///
80     }
81     else
82     {
83         alias int_fast16_t  = int;  ///
84         alias uint_fast16_t = uint; ///
85     }
86     alias int_fast32_t  = int32_t;  ///
87     alias uint_fast32_t = uint32_t; ///
88     alias int_fast64_t  = long;     ///
89     alias uint_fast64_t = ulong;    ///
90 
91     alias intptr_t  = ptrdiff_t; ///
92     alias uintptr_t = size_t;    ///
93     alias intmax_t  = long;      ///
94     alias uintmax_t = ulong;     ///
95 }
96 else version (Darwin)
97 {
98     alias int8_t   = byte;          ///
99     alias int16_t  = short;         ///
100     alias uint8_t  = ubyte;         ///
101     alias uint16_t = ushort;        ///
102     alias int32_t  = int;           ///
103     alias uint32_t = uint;          ///
104     alias int64_t  = cpp_longlong;  ///
105     alias uint64_t = cpp_ulonglong; ///
106 
107     alias int_least8_t   = byte;     ///
108     alias uint_least8_t  = ubyte;    ///
109     alias int_least16_t  = short;    ///
110     alias uint_least16_t = ushort;   ///
111     alias int_least32_t  = int;      ///
112     alias uint_least32_t = uint;     ///
113     alias int_least64_t  = int64_t;  ///
114     alias uint_least64_t = uint64_t; ///
115 
116     alias int_fast8_t   = byte;     ///
117     alias uint_fast8_t  = ubyte;    ///
118     alias int_fast16_t  = short;    ///
119     alias uint_fast16_t = ushort;   ///
120     alias int_fast32_t  = int;      ///
121     alias uint_fast32_t = uint;     ///
122     alias int_fast64_t  = int64_t;  ///
123     alias uint_fast64_t = uint64_t; ///
124 
125     alias intptr_t  = cpp_long;  ///
126     alias uintptr_t = cpp_ulong; ///
127     alias intmax_t  = long;      ///
128     alias uintmax_t = ulong;     ///
129 }
130 else version (linux)
131 {
132     alias int8_t   = byte;   ///
133     alias int16_t  = short;  ///
134     alias uint8_t  = ubyte;  ///
135     alias uint16_t = ushort; ///
136     alias int32_t  = int;    ///
137     alias uint32_t = uint;   ///
138     alias int64_t  = long;   ///
139     alias uint64_t = ulong;  ///
140 
141     alias int_least8_t   = byte;   ///
142     alias uint_least8_t  = ubyte;  ///
143     alias int_least16_t  = short;  ///
144     alias uint_least16_t = ushort; ///
145     alias int_least32_t  = int;    ///
146     alias uint_least32_t = uint;   ///
147     alias int_least64_t  = long;   ///
148     alias uint_least64_t = ulong;  ///
149 
150     version (CRuntime_Musl)
151     {
152         alias int_fast8_t   = byte;  ///
153         alias uint_fast8_t  = ubyte; ///
154         alias int_fast16_t  = int;   ///
155         alias uint_fast16_t = uint;  ///
156         alias int_fast32_t  = int;   ///
157         alias uint_fast32_t = uint;  ///
158     }
159     else
160     {
161         alias int_fast8_t   = byte;      ///
162         alias uint_fast8_t  = ubyte;     ///
163         alias int_fast16_t  = ptrdiff_t; ///
164         alias uint_fast16_t = size_t;    ///
165         alias int_fast32_t  = ptrdiff_t; ///
166         alias uint_fast32_t = size_t;    ///
167     }
168     alias int_fast64_t  = long;      ///
169     alias uint_fast64_t = ulong;     ///
170 
171     alias intptr_t  = ptrdiff_t; ///
172     alias uintptr_t = size_t;    ///
173     alias intmax_t  = long;      ///
174     alias uintmax_t = ulong;     ///
175 }
176 else version (CRuntime_Glibc)
177 {
178     alias int8_t   = byte;   ///
179     alias int16_t  = short;  ///
180     alias uint8_t  = ubyte;  ///
181     alias uint16_t = ushort; ///
182     alias int32_t  = int;    ///
183     alias uint32_t = uint;   ///
184     alias int64_t  = long;   ///
185     alias uint64_t = ulong;  ///
186 
187     alias int_least8_t   = byte;   ///
188     alias uint_least8_t  = ubyte;  ///
189     alias int_least16_t  = short;  ///
190     alias uint_least16_t = ushort; ///
191     alias int_least32_t  = int;    ///
192     alias uint_least32_t = uint;   ///
193     alias int_least64_t  = long;   ///
194     alias uint_least64_t = ulong;  ///
195 
196     alias int_fast8_t   = byte;      ///
197     alias uint_fast8_t  = ubyte;     ///
198     alias int_fast16_t  = ptrdiff_t; ///
199     alias uint_fast16_t = size_t;    ///
200     alias int_fast32_t  = ptrdiff_t; ///
201     alias uint_fast32_t = size_t;    ///
202     alias int_fast64_t  = long;      ///
203     alias uint_fast64_t = ulong;     ///
204 
205     alias intptr_t  = ptrdiff_t; ///
206     alias uintptr_t = size_t;    ///
207     alias intmax_t  = long;      ///
208     alias uintmax_t = ulong;     ///
209 }
210 else version (DragonFlyBSD)
211 {
212     alias int8_t   = byte;   ///
213     alias int16_t  = short;  ///
214     alias uint8_t  = ubyte;  ///
215     alias uint16_t = ushort; ///
216     alias int32_t  = int;    ///
217     alias uint32_t = uint;   ///
218     alias int64_t  = long;   ///
219     alias uint64_t = ulong;  ///
220 
221     alias int_least8_t   = int8_t;   ///
222     alias uint_least8_t  = uint8_t;  ///
223     alias int_least16_t  = int16_t;  ///
224     alias uint_least16_t = uint16_t; ///
225     alias int_least32_t  = int32_t;  ///
226     alias uint_least32_t = uint32_t; ///
227     alias int_least64_t  = int64_t;  ///
228     alias uint_least64_t = uint64_t; ///
229 
230     alias int_fast8_t   = int32_t;   ///
231     alias uint_fast8_t  = uint32_t;  ///
232     alias int_fast16_t  = int32_t;   ///
233     alias uint_fast16_t = uint32_t;  ///
234     alias int_fast32_t  = int32_t;   ///
235     alias uint_fast32_t = uint32_t;  ///
236     alias int_fast64_t  = int64_t;   ///
237     alias uint_fast64_t = uint64_t;  ///
238 
239     alias intptr_t  = ptrdiff_t; ///
240     alias uintptr_t = size_t;    ///
241     alias intmax_t  = long;      ///
242     alias uintmax_t = ulong;     ///
243 }
244 else version (FreeBSD)
245 {
246     alias int8_t   = byte;   ///
247     alias int16_t  = short;  ///
248     alias uint8_t  = ubyte;  ///
249     alias uint16_t = ushort; ///
250     alias int32_t  = int;    ///
251     alias uint32_t = uint;   ///
252     alias int64_t  = long;   ///
253     alias uint64_t = ulong;  ///
254 
255     alias int_least8_t   = byte;   ///
256     alias uint_least8_t  = ubyte;  ///
257     alias int_least16_t  = short;  ///
258     alias uint_least16_t = ushort; ///
259     alias int_least32_t  = int;    ///
260     alias uint_least32_t = uint;   ///
261     alias int_least64_t  = long;   ///
262     alias uint_least64_t = ulong;  ///
263 
264     alias int_fast8_t   = int;   ///
265     alias uint_fast8_t  = uint;  ///
266     alias int_fast16_t  = int;   ///
267     alias uint_fast16_t = uint;  ///
268     alias int_fast32_t  = int;   ///
269     alias uint_fast32_t = uint;  ///
270     alias int_fast64_t  = long;  ///
271     alias uint_fast64_t = ulong; ///
272 
273     alias intptr_t  = ptrdiff_t; ///
274     alias uintptr_t = size_t;    ///
275     alias intmax_t  = long;      ///
276     alias uintmax_t = ulong;     ///
277 }
278 else version (NetBSD)
279 {
280     alias int8_t   = byte;   ///
281     alias int16_t  = short;  ///
282     alias uint8_t  = ubyte;  ///
283     alias uint16_t = ushort; ///
284     alias int32_t  = int;    ///
285     alias uint32_t = uint;   ///
286     alias int64_t  = long;   ///
287     alias uint64_t = ulong;  ///
288 
289     alias int_least8_t   = int8_t;   ///
290     alias uint_least8_t  = uint8_t;  ///
291     alias int_least16_t  = int16_t;  ///
292     alias uint_least16_t = uint16_t; ///
293     alias int_least32_t  = int32_t;  ///
294     alias uint_least32_t = uint32_t; ///
295     alias int_least64_t  = int64_t;  ///
296     alias uint_least64_t = uint64_t; ///
297 
298     alias int_fast8_t   = int32_t;   ///
299     alias uint_fast8_t  = uint32_t;  ///
300     alias int_fast16_t  = int32_t;   ///
301     alias uint_fast16_t = uint32_t;  ///
302     alias int_fast32_t  = int32_t;   ///
303     alias uint_fast32_t = uint32_t;  ///
304     alias int_fast64_t  = int64_t;   ///
305     alias uint_fast64_t = uint64_t;  ///
306 
307     alias intptr_t  = ptrdiff_t; ///
308     alias uintptr_t = size_t;    ///
309     alias intmax_t  = long;      ///
310     alias uintmax_t = ulong;     ///
311 }
312 else version (OpenBSD)
313 {
314     alias int8_t   = byte;          ///
315     alias int16_t  = short;         ///
316     alias uint8_t  = ubyte;         ///
317     alias uint16_t = ushort;        ///
318     alias int32_t  = int;           ///
319     alias uint32_t = uint;          ///
320     alias int64_t  = cpp_longlong;  ///
321     alias uint64_t = cpp_ulonglong; ///
322 
323     alias int_least8_t   = byte;          ///
324     alias uint_least8_t  = ubyte;         ///
325     alias int_least16_t  = short;         ///
326     alias uint_least16_t = ushort;        ///
327     alias int_least32_t  = int;           ///
328     alias uint_least32_t = uint;          ///
329     alias int_least64_t  = cpp_longlong;  ///
330     alias uint_least64_t = cpp_ulonglong; ///
331 
332     alias int_fast8_t   = int;           ///
333     alias uint_fast8_t  = uint;          ///
334     alias int_fast16_t  = int;           ///
335     alias uint_fast16_t = uint;          ///
336     alias int_fast32_t  = int;           ///
337     alias uint_fast32_t = uint;          ///
338     alias int_fast64_t  = cpp_longlong;  ///
339     alias uint_fast64_t = cpp_ulonglong; ///
340 
341     alias intptr_t  = cpp_long;      ///
342     alias uintptr_t = cpp_ulong;     ///
343     alias intmax_t  = cpp_longlong;  ///
344     alias uintmax_t = cpp_ulonglong; ///
345 }
346 else version (Solaris)
347 {
348     alias int8_t   = char;   ///
349     alias int16_t  = short;  ///
350     alias uint8_t  = ubyte;  ///
351     alias uint16_t = ushort; ///
352     alias int32_t  = int;    ///
353     alias uint32_t = uint;   ///
354     alias int64_t  = long;   ///
355     alias uint64_t = ulong;  ///
356 
357     alias int_least8_t   = char;   ///
358     alias uint_least8_t  = ubyte;  ///
359     alias int_least16_t  = short;  ///
360     alias uint_least16_t = ushort; ///
361     alias int_least32_t  = int;    ///
362     alias uint_least32_t = uint;   ///
363     alias int_least64_t  = long;   ///
364     alias uint_least64_t = ulong;  ///
365 
366     alias int_fast8_t   = char;  ///
367     alias uint_fast8_t  = ubyte; ///
368     alias int_fast16_t  = int;   ///
369     alias uint_fast16_t = uint;  ///
370     alias int_fast32_t  = int;   ///
371     alias uint_fast32_t = uint;  ///
372     alias int_fast64_t  = long;  ///
373     alias uint_fast64_t = ulong; ///
374 
375     alias intptr_t  = ptrdiff_t; ///
376     alias uintptr_t = size_t;    ///
377     alias intmax_t  = long;      ///
378     alias uintmax_t = ulong;     ///
379 }
380 else version (WASI)
381 {
382     alias int8_t   = byte;   ///
383     alias int16_t  = short;  ///
384     alias uint8_t  = ubyte;  ///
385     alias uint16_t = ushort; ///
386     alias int32_t  = int;    ///
387     alias uint32_t = uint;   ///
388     alias int64_t  = long;   ///
389     alias uint64_t = ulong;  ///
390 
391     alias int_least8_t   = byte;   ///
392     alias uint_least8_t  = ubyte;  ///
393     alias int_least16_t  = short;  ///
394     alias uint_least16_t = ushort; ///
395     alias int_least32_t  = int;    ///
396     alias uint_least32_t = uint;   ///
397     alias int_least64_t  = long;   ///
398     alias uint_least64_t = ulong;  ///
399 
400     alias int_fast8_t   = byte;      ///
401     alias uint_fast8_t  = ubyte;     ///
402     alias int_fast16_t  = ptrdiff_t; ///
403     alias uint_fast16_t = size_t;    ///
404     alias int_fast32_t  = ptrdiff_t; ///
405     alias uint_fast32_t = size_t;    ///
406 
407     alias int_fast64_t  = long;      ///
408     alias uint_fast64_t = ulong;     ///
409 
410     alias intptr_t  = ptrdiff_t; ///
411     alias uintptr_t = size_t;    ///
412     alias intmax_t  = long;      ///
413     alias uintmax_t = ulong;     ///
414 }
415 else
416 {
417     static assert(false, "Unsupported architecture.");
418 }
419 
420 
421 
422 ///
423 enum int8_t   INT8_MIN  = int8_t.min;
424 ///
425 enum int8_t   INT8_MAX  = int8_t.max;
426 ///
427 enum int16_t  INT16_MIN = int16_t.min;
428 ///
429 enum int16_t  INT16_MAX = int16_t.max;
430 ///
431 enum int32_t  INT32_MIN = int32_t.min;
432 ///
433 enum int32_t  INT32_MAX = int32_t.max;
434 ///
435 enum int64_t  INT64_MIN = int64_t.min;
436 ///
437 enum int64_t  INT64_MAX = int64_t.max;
438 
439 ///
440 enum uint8_t  UINT8_MAX  = uint8_t.max;
441 ///
442 enum uint16_t UINT16_MAX = uint16_t.max;
443 ///
444 enum uint32_t UINT32_MAX = uint32_t.max;
445 ///
446 enum uint64_t UINT64_MAX = uint64_t.max;
447 
448 ///
449 enum int_least8_t    INT_LEAST8_MIN   = int_least8_t.min;
450 ///
451 enum int_least8_t    INT_LEAST8_MAX   = int_least8_t.max;
452 ///
453 enum int_least16_t   INT_LEAST16_MIN  = int_least16_t.min;
454 ///
455 enum int_least16_t   INT_LEAST16_MAX  = int_least16_t.max;
456 ///
457 enum int_least32_t   INT_LEAST32_MIN  = int_least32_t.min;
458 ///
459 enum int_least32_t   INT_LEAST32_MAX  = int_least32_t.max;
460 ///
461 enum int_least64_t   INT_LEAST64_MIN  = int_least64_t.min;
462 ///
463 enum int_least64_t   INT_LEAST64_MAX  = int_least64_t.max;
464 
465 ///
466 enum uint_least8_t   UINT_LEAST8_MAX  = uint_least8_t.max;
467 ///
468 enum uint_least16_t  UINT_LEAST16_MAX = uint_least16_t.max;
469 ///
470 enum uint_least32_t  UINT_LEAST32_MAX = uint_least32_t.max;
471 ///
472 enum uint_least64_t  UINT_LEAST64_MAX = uint_least64_t.max;
473 
474 ///
475 enum int_fast8_t   INT_FAST8_MIN   = int_fast8_t.min;
476 ///
477 enum int_fast8_t   INT_FAST8_MAX   = int_fast8_t.max;
478 ///
479 enum int_fast16_t  INT_FAST16_MIN  = int_fast16_t.min;
480 ///
481 enum int_fast16_t  INT_FAST16_MAX  = int_fast16_t.max;
482 ///
483 enum int_fast32_t  INT_FAST32_MIN  = int_fast32_t.min;
484 ///
485 enum int_fast32_t  INT_FAST32_MAX  = int_fast32_t.max;
486 ///
487 enum int_fast64_t  INT_FAST64_MIN  = int_fast64_t.min;
488 ///
489 enum int_fast64_t  INT_FAST64_MAX  = int_fast64_t.max;
490 
491 ///
492 enum uint_fast8_t  UINT_FAST8_MAX  = uint_fast8_t.max;
493 ///
494 enum uint_fast16_t UINT_FAST16_MAX = uint_fast16_t.max;
495 ///
496 enum uint_fast32_t UINT_FAST32_MAX = uint_fast32_t.max;
497 ///
498 enum uint_fast64_t UINT_FAST64_MAX = uint_fast64_t.max;
499 
500 ///
501 enum intptr_t  INTPTR_MIN  = intptr_t.min;
502 ///
503 enum intptr_t  INTPTR_MAX  = intptr_t.max;
504 
505 ///
506 enum uintptr_t UINTPTR_MIN = uintptr_t.min;
507 ///
508 enum uintptr_t UINTPTR_MAX = uintptr_t.max;
509 
510 ///
511 enum intmax_t  INTMAX_MIN  = intmax_t.min;
512 ///
513 enum intmax_t  INTMAX_MAX  = intmax_t.max;
514 
515 ///
516 enum uintmax_t UINTMAX_MAX = uintmax_t.max;
517 
518 ///
519 enum ptrdiff_t PTRDIFF_MIN = ptrdiff_t.min;
520 ///
521 enum ptrdiff_t PTRDIFF_MAX = ptrdiff_t.max;
522 
523 ///
524 enum sig_atomic_t SIG_ATOMIC_MIN = sig_atomic_t.min;
525 ///
526 enum sig_atomic_t SIG_ATOMIC_MAX = sig_atomic_t.max;
527 
528 ///
529 enum size_t  SIZE_MAX  = size_t.max;
530 
531 ///
532 enum wchar_t WCHAR_MIN = wchar_t.min;
533 ///
534 enum wchar_t WCHAR_MAX = wchar_t.max;
535 
536 ///
537 enum wint_t  WINT_MIN  = wint_t.min;
538 ///
539 enum wint_t  WINT_MAX  = wint_t.max;
540 
541 ///
542 alias INT8_C  = _typify!int8_t ;
543 ///
544 alias INT16_C = _typify!int16_t;
545 ///
546 alias INT32_C = _typify!int32_t;
547 ///
548 alias INT64_C = _typify!int64_t;
549 
550 ///
551 alias UINT8_C  = _typify!uint8_t ;
552 ///
553 alias UINT16_C = _typify!uint16_t;
554 ///
555 alias UINT32_C = _typify!uint32_t;
556 ///
557 alias UINT64_C = _typify!uint64_t;
558 
559 ///
560 alias INTMAX_C  = _typify!intmax_t ;
561 ///
562 alias UINTMAX_C = _typify!uintmax_t;