preproc: Add new %[...] indirection construct
[nasm/nasm.git] / inttypes / inttypes.h
blobe353aa93c1c4dc3007211fb7562f6f1989a57470
1 /*
2 * inttypes.h
4 * Small ersatz subset of <inttypes.h>, deriving the types from
5 * <limits.h>.
7 * Important: the preprocessor may truncate numbers too large for it.
8 * Therefore, test the signed types only ... truncation won't generate
9 * a 01111111... bit pattern.
12 #ifndef INTTYPES_H
13 #define INTTYPES_H
15 #include <limits.h>
17 /*** 64-bit type: long or long long ***/
19 /* Some old versions of gcc <limits.h> omit LLONG_MAX */
20 #ifndef LLONG_MAX
21 # ifdef __LONG_LONG_MAX__
22 # define LLONG_MAX __LONG_LONG_MAX__
23 # else
24 # define LLONG_MAX 0 /* Assume long long is unusable */
25 # endif
26 #endif
28 #if LONG_MAX == 9223372036854775807L
30 /* long is 64 bits */
31 typedef signed long int64_t;
32 typedef unsigned long uint64_t;
33 #define _scn64 "l"
34 #define _pri64 "l"
35 #define INT64_C(x) x ## L
36 #define UINT64_C(x) x ## UL
38 #elif LLONG_MAX == 9223372036854775807LL
40 /* long long is 64 bits */
41 typedef signed long long int64_t;
42 typedef unsigned long long uint64_t;
43 #define _scn64 "ll"
44 #define _pri64 "ll"
45 #define INT64_C(x) x ## LL
46 #define UINT64_C(x) x ## ULL
48 #else
50 #error "Neither long nor long long is 64 bits in size"
52 #endif
54 /*** 32-bit type: int or long ***/
56 #if INT_MAX == 2147483647
58 /* int is 32 bits */
59 typedef signed int int32_t;
60 typedef unsigned int uint32_t;
61 #define _scn32 ""
62 #define _pri32 ""
63 #define INT32_C(x) x
64 #define UINT32_C(x) x ## U
66 #elif LONG_MAX == 2147483647L
68 /* long is 32 bits */
69 typedef signed long int32_t;
70 typedef unsigned long uint32_t;
71 #define _scn32 "l"
72 #define _pri32 "l"
73 #define INT32_C(x) x ## L
74 #define UINT32_C(x) x ## UL
76 #else
78 #error "Neither int nor long is 32 bits in size"
80 #endif
82 /*** 16-bit size: int or short ***/
84 #if INT_MAX == 32767
86 /* int is 16 bits */
87 typedef signed int int16_t;
88 typedef unsigned int uint16_t;
89 #define _scn16 ""
90 #define _pri16 ""
91 #define INT16_C(x) x
92 #define UINT16_C(x) x ## U
94 #elif SHRT_MAX == 32767
96 /* short is 16 bits */
97 typedef signed short int16_t;
98 typedef unsigned short uint16_t;
99 #define _scn16 "h"
100 #define _pri16 ""
101 #define INT16_C(x) x
102 #define UINT16_C(x) x ## U
104 #else
106 #error "Neither short nor int is 16 bits in size"
108 #endif
110 /*** 8-bit size: char ***/
112 #if SCHAR_MAX == 127
114 /* char is 8 bits */
115 typedef signed char int8_t;
116 typedef unsigned char uint8_t;
117 #define _scn8 "hh"
118 #define _pri8 ""
119 #define INT8_C(x) x
120 #define UINT8_C(x) x ## U
122 #else
124 #error "char is not 8 bits in size"
126 #endif
128 /* The rest of this is common to all models */
130 #define PRId8 _pri8 "d"
131 #define PRId16 _pri16 "d"
132 #define PRId32 _pri32 "d"
133 #define PRId64 _pri64 "d"
135 #define PRIi8 _pri8 "i"
136 #define PRIi16 _pri16 "i"
137 #define PRIi32 _pri32 "i"
138 #define PRIi64 _pri64 "i"
140 #define PRIo8 _pri8 "o"
141 #define PRIo16 _pri16 "o"
142 #define PRIo32 _pri32 "o"
143 #define PRIo64 _pri64 "o"
145 #define PRIu8 _pri8 "u"
146 #define PRIu16 _pri16 "u"
147 #define PRIu32 _pri32 "u"
148 #define PRIu64 _pri64 "u"
150 #define PRIx8 _pri8 "x"
151 #define PRIx16 _pri16 "x"
152 #define PRIx32 _pri32 "x"
153 #define PRIx64 _pri64 "x"
155 #define PRIX8 _pri8 "X"
156 #define PRIX16 _pri16 "X"
157 #define PRIX32 _pri32 "X"
158 #define PRIX64 _pri64 "X"
160 #define SCNd8 _scn8 "d"
161 #define SCNd16 _scn16 "d"
162 #define SCNd32 _scn32 "d"
163 #define SCNd64 _scn64 "d"
165 #define SCNi8 _scn8 "i"
166 #define SCNi16 _scn16 "i"
167 #define SCNi32 _scn32 "i"
168 #define SCNi64 _scn64 "i"
170 #define SCNo8 _scn8 "o"
171 #define SCNo16 _scn16 "o"
172 #define SCNo32 _scn32 "o"
173 #define SCNo64 _scn64 "o"
175 #define SCNu8 _scn8 "u"
176 #define SCNu16 _scn16 "u"
177 #define SCNu32 _scn32 "u"
178 #define SCNu64 _scn64 "u"
180 #define SCNx8 _scn8 "x"
181 #define SCNx16 _scn16 "x"
182 #define SCNx32 _scn32 "x"
183 #define SCNx64 _scn64 "x"
185 #define INT8_MIN INT8_C(-128)
186 #define INT8_MAX INT8_C(127)
187 #define UINT8_MAX UINT8_C(255)
189 #define INT16_MIN INT16_C(-32768)
190 #define INT16_MAX INT16_C(32767)
191 #define UINT16_MAX UINT16_C(65535)
193 #define INT32_MIN INT32_C(-2147483648)
194 #define INT32_MAX INT32_C(2147483647)
195 #define UINT32_MAX UINT32_C(4294967295)
197 #define INT64_MIN INT64_C(-9223372036854775808)
198 #define INT64_MAX INT64_C(9223372036854775807)
199 #define UINT64_MAX UINT64_C(18446744073709551615)
201 #endif /* INTTYPES_H */