ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
pstdint.h
Go to the documentation of this file.
1/* A portable stdint.h
2 ****************************************************************************
3 * BSD License:
4 ****************************************************************************
5 *
6 * Copyright (c) 2005-2014 Paul Hsieh
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 ****************************************************************************
33 *
34 * Version 0.1.14
35 *
36 * The ANSI C standard committee, for the C99 standard, specified the
37 * inclusion of a new standard include file called stdint.h. This is
38 * a very useful and long desired include file which contains several
39 * very precise definitions for integer scalar types that is
40 * critically important for making portable several classes of
41 * applications including cryptography, hashing, variable length
42 * integer libraries and so on. But for most developers its likely
43 * useful just for programming sanity.
44 *
45 * The problem is that most compiler vendors have decided not to
46 * implement the C99 standard, and the next C++ language standard
47 * (which has a lot more mindshare these days) will be a long time in
48 * coming and its unknown whether or not it will include stdint.h or
49 * how much adoption it will have. Either way, it will be a long time
50 * before all compilers come with a stdint.h and it also does nothing
51 * for the extremely large number of compilers available today which
52 * do not include this file, or anything comparable to it.
53 *
54 * So that's what this file is all about. Its an attempt to build a
55 * single universal include file that works on as many platforms as
56 * possible to deliver what stdint.h is supposed to. A few things
57 * that should be noted about this file:
58 *
59 * 1) It is not guaranteed to be portable and/or present an identical
60 * interface on all platforms. The extreme variability of the
61 * ANSI C standard makes this an impossibility right from the
62 * very get go. Its really only meant to be useful for the vast
63 * majority of platforms that possess the capability of
64 * implementing usefully and precisely defined, standard sized
65 * integer scalars. Systems which are not intrinsically 2s
66 * complement may produce invalid constants.
67 *
68 * 2) There is an unavoidable use of non-reserved symbols.
69 *
70 * 3) Other standard include files are invoked.
71 *
72 * 4) This file may come in conflict with future platforms that do
73 * include stdint.h. The hope is that one or the other can be
74 * used with no real difference.
75 *
76 * 5) In the current verison, if your platform can't represent
77 * int32_t, int16_t and int8_t, it just dumps out with a compiler
78 * error.
79 *
80 * 6) 64 bit integers may or may not be defined. Test for their
81 * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
82 * Note that this is different from the C99 specification which
83 * requires the existence of 64 bit support in the compiler. If
84 * this is not defined for your platform, yet it is capable of
85 * dealing with 64 bits then it is because this file has not yet
86 * been extended to cover all of your system's capabilities.
87 *
88 * 7) (u)intptr_t may or may not be defined. Test for its presence
89 * with the test: #ifdef PTRDIFF_MAX. If this is not defined
90 * for your platform, then it is because this file has not yet
91 * been extended to cover all of your system's capabilities, not
92 * because its optional.
93 *
94 * 8) The following might not been defined even if your platform is
95 * capable of defining it:
96 *
97 * WCHAR_MIN
98 * WCHAR_MAX
99 * (u)int64_t
100 * PTRDIFF_MIN
101 * PTRDIFF_MAX
102 * (u)intptr_t
103 *
104 * 9) The following have not been defined:
105 *
106 * WINT_MIN
107 * WINT_MAX
108 *
109 * 10) The criteria for defining (u)int_least(*)_t isn't clear,
110 * except for systems which don't have a type that precisely
111 * defined 8, 16, or 32 bit types (which this include file does
112 * not support anyways). Default definitions have been given.
113 *
114 * 11) The criteria for defining (u)int_fast(*)_t isn't something I
115 * would trust to any particular compiler vendor or the ANSI C
116 * committee. It is well known that "compatible systems" are
117 * commonly created that have very different performance
118 * characteristics from the systems they are compatible with,
119 * especially those whose vendors make both the compiler and the
120 * system. Default definitions have been given, but its strongly
121 * recommended that users never use these definitions for any
122 * reason (they do *NOT* deliver any serious guarantee of
123 * improved performance -- not in this file, nor any vendor's
124 * stdint.h).
125 *
126 * 12) The following macros:
127 *
128 * PRINTF_INTMAX_MODIFIER
129 * PRINTF_INT64_MODIFIER
130 * PRINTF_INT32_MODIFIER
131 * PRINTF_INT16_MODIFIER
132 * PRINTF_LEAST64_MODIFIER
133 * PRINTF_LEAST32_MODIFIER
134 * PRINTF_LEAST16_MODIFIER
135 * PRINTF_INTPTR_MODIFIER
136 *
137 * are strings which have been defined as the modifiers required
138 * for the "d", "u" and "x" printf formats to correctly output
139 * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
140 * (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
141 * PRINTF_INTPTR_MODIFIER is not defined for some systems which
142 * provide their own stdint.h. PRINTF_INT64_MODIFIER is not
143 * defined if INT64_MAX is not defined. These are an extension
144 * beyond what C99 specifies must be in stdint.h.
145 *
146 * In addition, the following macros are defined:
147 *
148 * PRINTF_INTMAX_HEX_WIDTH
149 * PRINTF_INT64_HEX_WIDTH
150 * PRINTF_INT32_HEX_WIDTH
151 * PRINTF_INT16_HEX_WIDTH
152 * PRINTF_INT8_HEX_WIDTH
153 * PRINTF_INTMAX_DEC_WIDTH
154 * PRINTF_INT64_DEC_WIDTH
155 * PRINTF_INT32_DEC_WIDTH
156 * PRINTF_INT16_DEC_WIDTH
157 * PRINTF_INT8_DEC_WIDTH
158 *
159 * Which specifies the maximum number of characters required to
160 * print the number of that type in either hexadecimal or decimal.
161 * These are an extension beyond what C99 specifies must be in
162 * stdint.h.
163 *
164 * Compilers tested (all with 0 warnings at their highest respective
165 * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
166 * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
167 * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
168 *
169 * This file should be considered a work in progress. Suggestions for
170 * improvements, especially those which increase coverage are strongly
171 * encouraged.
172 *
173 * Acknowledgements
174 *
175 * The following people have made significant contributions to the
176 * development and testing of this file:
177 *
178 * Chris Howie
179 * John Steele Scott
180 * Dave Thorup
181 * John Dill
182 * Florian Wobbe
183 * Christopher Sean Morrison
184 *
185 */
186
187#include <stddef.h>
188#include <limits.h>
189#include <signal.h>
190
191/*
192 * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
193 * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
194 */
195
196#if ((defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (__GNUC__ > 3 || defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) )) && !defined (_PSTDINT_H_INCLUDED)
197#include <stdint.h>
198#define _PSTDINT_H_INCLUDED
199# if defined(__GNUC__) && (defined(__x86_64__) || defined(__ppc64__))
200# ifndef PRINTF_INT64_MODIFIER
201# define PRINTF_INT64_MODIFIER "l"
202# endif
203# ifndef PRINTF_INT32_MODIFIER
204# define PRINTF_INT32_MODIFIER ""
205# endif
206# else
207# ifndef PRINTF_INT64_MODIFIER
208# define PRINTF_INT64_MODIFIER "ll"
209# endif
210# ifndef PRINTF_INT32_MODIFIER
211# define PRINTF_INT32_MODIFIER "l"
212# endif
213# endif
214# ifndef PRINTF_INT16_MODIFIER
215# define PRINTF_INT16_MODIFIER "h"
216# endif
217# ifndef PRINTF_INTMAX_MODIFIER
218# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
219# endif
220# ifndef PRINTF_INT64_HEX_WIDTH
221# define PRINTF_INT64_HEX_WIDTH "16"
222# endif
223# ifndef PRINTF_INT32_HEX_WIDTH
224# define PRINTF_INT32_HEX_WIDTH "8"
225# endif
226# ifndef PRINTF_INT16_HEX_WIDTH
227# define PRINTF_INT16_HEX_WIDTH "4"
228# endif
229# ifndef PRINTF_INT8_HEX_WIDTH
230# define PRINTF_INT8_HEX_WIDTH "2"
231# endif
232# ifndef PRINTF_INT64_DEC_WIDTH
233# define PRINTF_INT64_DEC_WIDTH "20"
234# endif
235# ifndef PRINTF_INT32_DEC_WIDTH
236# define PRINTF_INT32_DEC_WIDTH "10"
237# endif
238# ifndef PRINTF_INT16_DEC_WIDTH
239# define PRINTF_INT16_DEC_WIDTH "5"
240# endif
241# ifndef PRINTF_INT8_DEC_WIDTH
242# define PRINTF_INT8_DEC_WIDTH "3"
243# endif
244# ifndef PRINTF_INTMAX_HEX_WIDTH
245# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
246# endif
247# ifndef PRINTF_INTMAX_DEC_WIDTH
248# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
249# endif
250
251/*
252 * Something really weird is going on with Open Watcom. Just pull some of
253 * these duplicated definitions from Open Watcom's stdint.h file for now.
254 */
255
256# if defined (__WATCOMC__) && __WATCOMC__ >= 1250
257# if !defined (INT64_C)
258# define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
259# endif
260# if !defined (UINT64_C)
261# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
262# endif
263# if !defined (INT32_C)
264# define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
265# endif
266# if !defined (UINT32_C)
267# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
268# endif
269# if !defined (INT16_C)
270# define INT16_C(x) (x)
271# endif
272# if !defined (UINT16_C)
273# define UINT16_C(x) (x)
274# endif
275# if !defined (INT8_C)
276# define INT8_C(x) (x)
277# endif
278# if !defined (UINT8_C)
279# define UINT8_C(x) (x)
280# endif
281# if !defined (UINT64_MAX)
282# define UINT64_MAX 18446744073709551615ULL
283# endif
284# if !defined (INT64_MAX)
285# define INT64_MAX 9223372036854775807LL
286# endif
287# if !defined (UINT32_MAX)
288# define UINT32_MAX 4294967295UL
289# endif
290# if !defined (INT32_MAX)
291# define INT32_MAX 2147483647L
292# endif
293# if !defined (INTMAX_MAX)
294# define INTMAX_MAX INT64_MAX
295# endif
296# if !defined (INTMAX_MIN)
297# define INTMAX_MIN INT64_MIN
298# endif
299# endif
300#endif
301
302#ifndef _PSTDINT_H_INCLUDED
303#define _PSTDINT_H_INCLUDED
304
305#ifndef SIZE_MAX
306# define SIZE_MAX (~(size_t)0)
307#endif
308
309/*
310 * Deduce the type assignments from limits.h under the assumption that
311 * integer sizes in bits are powers of 2, and follow the ANSI
312 * definitions.
313 */
314
315#ifndef UINT8_MAX
316# define UINT8_MAX 0xff
317#endif
318#if !defined(uint8_t) && !defined(_UINT8_T)
319# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
320 typedef unsigned char uint8_t;
321# define UINT8_C(v) ((uint8_t) v)
322# else
323# error "Platform not supported"
324# endif
325#endif
326
327#ifndef INT8_MAX
328# define INT8_MAX 0x7f
329#endif
330#ifndef INT8_MIN
331# define INT8_MIN INT8_C(0x80)
332#endif
333#if !defined(int8_t) && !defined(_INT8_T)
334# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
335 typedef signed char int8_t;
336# define INT8_C(v) ((int8_t) v)
337# else
338# error "Platform not supported"
339# endif
340#endif
341
342#ifndef UINT16_MAX
343# define UINT16_MAX 0xffff
344#endif
345#if !defined(uint16_t) && !defined(_UINT16_T)
346#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
347 typedef unsigned int uint16_t;
348# ifndef PRINTF_INT16_MODIFIER
349# define PRINTF_INT16_MODIFIER ""
350# endif
351# define UINT16_C(v) ((uint16_t) (v))
352#elif (USHRT_MAX == UINT16_MAX)
353 typedef unsigned short uint16_t;
354# define UINT16_C(v) ((uint16_t) (v))
355# ifndef PRINTF_INT16_MODIFIER
356# define PRINTF_INT16_MODIFIER "h"
357# endif
358#else
359#error "Platform not supported"
360#endif
361#endif
362
363#ifndef INT16_MAX
364# define INT16_MAX 0x7fff
365#endif
366#ifndef INT16_MIN
367# define INT16_MIN INT16_C(0x8000)
368#endif
369#if !defined(int16_t) && !defined(_INT16_T)
370#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
371 typedef signed int int16_t;
372# define INT16_C(v) ((int16_t) (v))
373# ifndef PRINTF_INT16_MODIFIER
374# define PRINTF_INT16_MODIFIER ""
375# endif
376#elif (SHRT_MAX == INT16_MAX)
377 typedef signed short int16_t;
378# define INT16_C(v) ((int16_t) (v))
379# ifndef PRINTF_INT16_MODIFIER
380# define PRINTF_INT16_MODIFIER "h"
381# endif
382#else
383#error "Platform not supported"
384#endif
385#endif
386
387#ifndef UINT32_MAX
388# define UINT32_MAX (0xffffffffUL)
389#endif
390#if !defined(uint32_t) && !defined(_UINT32_T)
391#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
392 typedef unsigned long uint32_t;
393# define UINT32_C(v) v ## UL
394# ifndef PRINTF_INT32_MODIFIER
395# define PRINTF_INT32_MODIFIER "l"
396# endif
397#elif (UINT_MAX == UINT32_MAX)
398 typedef unsigned int uint32_t;
399# ifndef PRINTF_INT32_MODIFIER
400# define PRINTF_INT32_MODIFIER ""
401# endif
402# define UINT32_C(v) v ## U
403#elif (USHRT_MAX == UINT32_MAX)
404 typedef unsigned short uint32_t;
405# define UINT32_C(v) ((unsigned short) (v))
406# ifndef PRINTF_INT32_MODIFIER
407# define PRINTF_INT32_MODIFIER ""
408# endif
409#else
410#error "Platform not supported"
411#endif
412#endif
413
414#ifndef INT32_MAX
415# define INT32_MAX (0x7fffffffL)
416#endif
417#ifndef INT32_MIN
418# define INT32_MIN INT32_C(0x80000000)
419#endif
420#if !defined(int32_t) && !defined(_INT32_T)
421#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
422 typedef signed long int32_t;
423# define INT32_C(v) v ## L
424# ifndef PRINTF_INT32_MODIFIER
425# define PRINTF_INT32_MODIFIER "l"
426# endif
427#elif (INT_MAX == INT32_MAX)
428 typedef signed int int32_t;
429# define INT32_C(v) v
430# ifndef PRINTF_INT32_MODIFIER
431# define PRINTF_INT32_MODIFIER ""
432# endif
433#elif (SHRT_MAX == INT32_MAX)
434 typedef signed short int32_t;
435# define INT32_C(v) ((short) (v))
436# ifndef PRINTF_INT32_MODIFIER
437# define PRINTF_INT32_MODIFIER ""
438# endif
439#else
440#error "Platform not supported"
441#endif
442#endif
443
444/*
445 * The macro stdint_int64_defined is temporarily used to record
446 * whether or not 64 integer support is available. It must be
447 * defined for any 64 integer extensions for new platforms that are
448 * added.
449 */
450
451#undef stdint_int64_defined
452#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
453# if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined (S_SPLINT_S)
454# define stdint_int64_defined
455 typedef long long int64_t;
456 typedef unsigned long long uint64_t;
457# define UINT64_C(v) v ## ULL
458# define INT64_C(v) v ## LL
459# ifndef PRINTF_INT64_MODIFIER
460# define PRINTF_INT64_MODIFIER "ll"
461# endif
462# endif
463#endif
464
465#if !defined (stdint_int64_defined)
466# if defined(__GNUC__)
467# define stdint_int64_defined
468 __extension__ typedef long long int64_t;
469 __extension__ typedef unsigned long long uint64_t;
470# define UINT64_C(v) v ## ULL
471# define INT64_C(v) v ## LL
472# ifndef PRINTF_INT64_MODIFIER
473# define PRINTF_INT64_MODIFIER "ll"
474# endif
475# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
476# define stdint_int64_defined
477 typedef long long int64_t;
478 typedef unsigned long long uint64_t;
479# define UINT64_C(v) v ## ULL
480# define INT64_C(v) v ## LL
481# ifndef PRINTF_INT64_MODIFIER
482# define PRINTF_INT64_MODIFIER "ll"
483# endif
484# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
485# define stdint_int64_defined
486 typedef __int64 int64_t;
487 typedef unsigned __int64 uint64_t;
488# define UINT64_C(v) v ## UI64
489# define INT64_C(v) v ## I64
490# ifndef PRINTF_INT64_MODIFIER
491# define PRINTF_INT64_MODIFIER "I64"
492# endif
493# endif
494#endif
495
496#if !defined (LONG_LONG_MAX) && defined (INT64_C)
497# define LONG_LONG_MAX INT64_C (9223372036854775807)
498#endif
499#ifndef ULONG_LONG_MAX
500# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
501#endif
502
503#if !defined (INT64_MAX) && defined (INT64_C)
504# define INT64_MAX INT64_C (9223372036854775807)
505#endif
506#if !defined (INT64_MIN) && defined (INT64_C)
507# define INT64_MIN INT64_C (-9223372036854775808)
508#endif
509#if !defined (UINT64_MAX) && defined (INT64_C)
510# define UINT64_MAX UINT64_C (18446744073709551615)
511#endif
512
513/*
514 * Width of hexadecimal for number field.
515 */
516
517#ifndef PRINTF_INT64_HEX_WIDTH
518# define PRINTF_INT64_HEX_WIDTH "16"
519#endif
520#ifndef PRINTF_INT32_HEX_WIDTH
521# define PRINTF_INT32_HEX_WIDTH "8"
522#endif
523#ifndef PRINTF_INT16_HEX_WIDTH
524# define PRINTF_INT16_HEX_WIDTH "4"
525#endif
526#ifndef PRINTF_INT8_HEX_WIDTH
527# define PRINTF_INT8_HEX_WIDTH "2"
528#endif
529
530#ifndef PRINTF_INT64_DEC_WIDTH
531# define PRINTF_INT64_DEC_WIDTH "20"
532#endif
533#ifndef PRINTF_INT32_DEC_WIDTH
534# define PRINTF_INT32_DEC_WIDTH "10"
535#endif
536#ifndef PRINTF_INT16_DEC_WIDTH
537# define PRINTF_INT16_DEC_WIDTH "5"
538#endif
539#ifndef PRINTF_INT8_DEC_WIDTH
540# define PRINTF_INT8_DEC_WIDTH "3"
541#endif
542
543/*
544 * Ok, lets not worry about 128 bit integers for now. Moore's law says
545 * we don't need to worry about that until about 2040 at which point
546 * we'll have bigger things to worry about.
547 */
548
549#ifdef stdint_int64_defined
550 typedef int64_t intmax_t;
551 typedef uint64_t uintmax_t;
552# define INTMAX_MAX INT64_MAX
553# define INTMAX_MIN INT64_MIN
554# define UINTMAX_MAX UINT64_MAX
555# define UINTMAX_C(v) UINT64_C(v)
556# define INTMAX_C(v) INT64_C(v)
557# ifndef PRINTF_INTMAX_MODIFIER
558# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
559# endif
560# ifndef PRINTF_INTMAX_HEX_WIDTH
561# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
562# endif
563# ifndef PRINTF_INTMAX_DEC_WIDTH
564# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
565# endif
566#else
567 typedef int32_t intmax_t;
569# define INTMAX_MAX INT32_MAX
570# define UINTMAX_MAX UINT32_MAX
571# define UINTMAX_C(v) UINT32_C(v)
572# define INTMAX_C(v) INT32_C(v)
573# ifndef PRINTF_INTMAX_MODIFIER
574# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
575# endif
576# ifndef PRINTF_INTMAX_HEX_WIDTH
577# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
578# endif
579# ifndef PRINTF_INTMAX_DEC_WIDTH
580# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
581# endif
582#endif
583
584/*
585 * Because this file currently only supports platforms which have
586 * precise powers of 2 as bit sizes for the default integers, the
587 * least definitions are all trivial. Its possible that a future
588 * version of this file could have different definitions.
589 */
590
591#ifndef stdint_least_defined
592 typedef int8_t int_least8_t;
594 typedef int16_t int_least16_t;
595 typedef uint16_t uint_least16_t;
596 typedef int32_t int_least32_t;
598# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
599# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
600# define UINT_LEAST8_MAX UINT8_MAX
601# define INT_LEAST8_MAX INT8_MAX
602# define UINT_LEAST16_MAX UINT16_MAX
603# define INT_LEAST16_MAX INT16_MAX
604# define UINT_LEAST32_MAX UINT32_MAX
605# define INT_LEAST32_MAX INT32_MAX
606# define INT_LEAST8_MIN INT8_MIN
607# define INT_LEAST16_MIN INT16_MIN
608# define INT_LEAST32_MIN INT32_MIN
609# ifdef stdint_int64_defined
610 typedef int64_t int_least64_t;
611 typedef uint64_t uint_least64_t;
612# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
613# define UINT_LEAST64_MAX UINT64_MAX
614# define INT_LEAST64_MAX INT64_MAX
615# define INT_LEAST64_MIN INT64_MIN
616# endif
617#endif
618#undef stdint_least_defined
619
620/*
621 * The ANSI C committee pretending to know or specify anything about
622 * performance is the epitome of misguided arrogance. The mandate of
623 * this file is to *ONLY* ever support that absolute minimum
624 * definition of the fast integer types, for compatibility purposes.
625 * No extensions, and no attempt to suggest what may or may not be a
626 * faster integer type will ever be made in this file. Developers are
627 * warned to stay away from these types when using this or any other
628 * stdint.h.
629 */
630
637#define UINT_FAST8_MAX UINT_LEAST8_MAX
638#define INT_FAST8_MAX INT_LEAST8_MAX
639#define UINT_FAST16_MAX UINT_LEAST16_MAX
640#define INT_FAST16_MAX INT_LEAST16_MAX
641#define UINT_FAST32_MAX UINT_LEAST32_MAX
642#define INT_FAST32_MAX INT_LEAST32_MAX
643#define INT_FAST8_MIN INT_LEAST8_MIN
644#define INT_FAST16_MIN INT_LEAST16_MIN
645#define INT_FAST32_MIN INT_LEAST32_MIN
646#ifdef stdint_int64_defined
647 typedef int_least64_t int_fast64_t;
648 typedef uint_least64_t uint_fast64_t;
649# define UINT_FAST64_MAX UINT_LEAST64_MAX
650# define INT_FAST64_MAX INT_LEAST64_MAX
651# define INT_FAST64_MIN INT_LEAST64_MIN
652#endif
653
654#undef stdint_int64_defined
655
656/*
657 * Whatever piecemeal, per compiler thing we can do about the wchar_t
658 * type limits.
659 */
660
661#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
662# include <wchar.h>
663# ifndef WCHAR_MIN
664# define WCHAR_MIN 0
665# endif
666# ifndef WCHAR_MAX
667# define WCHAR_MAX ((wchar_t)-1)
668# endif
669#endif
670
671/*
672 * Whatever piecemeal, per compiler/platform thing we can do about the
673 * (u)intptr_t types and limits.
674 */
675
676#if (defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)) || defined (_UINTPTR_T)
677# define STDINT_H_UINTPTR_T_DEFINED
678#endif
679
680#ifndef STDINT_H_UINTPTR_T_DEFINED
681# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64) || defined (__ppc64__)
682# define stdint_intptr_bits 64
683# elif defined (__WATCOMC__) || defined (__TURBOC__)
684# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
685# define stdint_intptr_bits 16
686# else
687# define stdint_intptr_bits 32
688# endif
689# elif defined (__i386__) || defined (_WIN32) || defined (WIN32) || defined (__ppc64__)
690# define stdint_intptr_bits 32
691# elif defined (__INTEL_COMPILER)
692/* TODO -- what did Intel do about x86-64? */
693# else
694/* #error "This platform might not be supported yet" */
695# endif
696
697# ifdef stdint_intptr_bits
698# define stdint_intptr_glue3_i(a,b,c) a##b##c
699# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
700# ifndef PRINTF_INTPTR_MODIFIER
701# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
702# endif
703# ifndef PTRDIFF_MAX
704# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
705# endif
706# ifndef PTRDIFF_MIN
707# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
708# endif
709# ifndef UINTPTR_MAX
710# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
711# endif
712# ifndef INTPTR_MAX
713# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
714# endif
715# ifndef INTPTR_MIN
716# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
717# endif
718# ifndef INTPTR_C
719# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
720# endif
721# ifndef UINTPTR_C
722# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
723# endif
724 typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
725 typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
726# else
727/* TODO -- This following is likely wrong for some platforms, and does
728 nothing for the definition of uintptr_t. */
729 typedef ptrdiff_t intptr_t;
730# endif
731# define STDINT_H_UINTPTR_T_DEFINED
732#endif
733
734/*
735 * Assumes sig_atomic_t is signed and we have a 2s complement machine.
736 */
737
738#ifndef SIG_ATOMIC_MAX
739# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
740#endif
741
742#endif
743
744#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
745
746/*
747 * Please compile with the maximum warning settings to make sure macros are not
748 * defined more than once.
749 */
750
751#include <stdlib.h>
752#include <stdio.h>
753#include <string.h>
754
755#define glue3_aux(x,y,z) x ## y ## z
756#define glue3(x,y,z) glue3_aux(x,y,z)
757
758#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,) = glue3(UINT,bits,_C) (0);
759#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,) = glue3(INT,bits,_C) (0);
760
761#define DECL(us,bits) glue3(DECL,us,) (bits)
762
763#define TESTUMAX(bits) glue3(u,bits,) = ~glue3(u,bits,); if (glue3(UINT,bits,_MAX) != glue3(u,bits,)) printf ("Something wrong with UINT%d_MAX\n", bits)
764
765int main () {
766 DECL(I,8)
767 DECL(U,8)
768 DECL(I,16)
769 DECL(U,16)
770 DECL(I,32)
771 DECL(U,32)
772#ifdef INT64_MAX
773 DECL(I,64)
774 DECL(U,64)
775#endif
776 intmax_t imax = INTMAX_C(0);
777 uintmax_t umax = UINTMAX_C(0);
778 char str0[256], str1[256];
779
780 sprintf (str0, "%d %x\n", 0, ~0);
781
782 sprintf (str1, "%d %x\n", i8, ~0);
783 if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
784 sprintf (str1, "%u %x\n", u8, ~0);
785 if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
786 sprintf (str1, "%d %x\n", i16, ~0);
787 if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
788 sprintf (str1, "%u %x\n", u16, ~0);
789 if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
790 sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
791 if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
792 sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
793 if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
794#ifdef INT64_MAX
795 sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
796 if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
797#endif
798 sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
799 if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
800 sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
801 if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);
802
803 TESTUMAX(8);
804 TESTUMAX(16);
805 TESTUMAX(32);
806#ifdef INT64_MAX
807 TESTUMAX(64);
808#endif
809
810 return EXIT_SUCCESS;
811}
812
813#endif
unsigned int uint32_t
Definition Fxch.h:32
ABC_NAMESPACE_HEADER_START typedef unsigned char uint8_t
Definition Fxch.h:31
ABC_NAMESPACE_IMPL_END int main(int argc, char *argv[])
GLOBAL VARIABLES ///.
Definition main.c:9
int16_t int_least16_t
Definition pstdint.h:594
int32_t intmax_t
Definition pstdint.h:567
int32_t int_least32_t
Definition pstdint.h:596
int_least16_t int_fast16_t
Definition pstdint.h:633
uint16_t uint_least16_t
Definition pstdint.h:595
uint_least32_t uint_fast32_t
Definition pstdint.h:636
#define UINTMAX_C(v)
Definition pstdint.h:571
#define INTMAX_C(v)
Definition pstdint.h:572
uint32_t uintmax_t
Definition pstdint.h:568
int_least8_t int_fast8_t
Definition pstdint.h:631
int8_t int_least8_t
Definition pstdint.h:592
uint32_t uint_least32_t
Definition pstdint.h:597
ptrdiff_t intptr_t
Definition pstdint.h:729
uint8_t uint_least8_t
Definition pstdint.h:593
uint_least16_t uint_fast16_t
Definition pstdint.h:634
#define PRINTF_INTMAX_MODIFIER
Definition pstdint.h:574
int_least32_t int_fast32_t
Definition pstdint.h:635
uint_least8_t uint_fast8_t
Definition pstdint.h:632
int strcmp()
char * sprintf()