4 * Small ersatz subset of <inttypes.h>, deriving the types from
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.
17 /*** 64-bit type: long or long long ***/
19 /* Some old versions of gcc <limits.h> omit LLONG_MAX */
21 # ifdef __LONG_LONG_MAX__
22 # define LLONG_MAX __LONG_LONG_MAX__
24 # define LLONG_MAX 0 /* Assume long long is unusable */
28 #if LONG_MAX == 9223372036854775807L
31 typedef signed long int64_t;
32 typedef unsigned long uint64_t;
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;
45 #define INT64_C(x) x ## LL
46 #define UINT64_C(x) x ## ULL
50 #error "Neither long nor long long is 64 bits in size"
54 /*** 32-bit type: int or long ***/
56 #if INT_MAX == 2147483647
59 typedef signed int int32_t;
60 typedef unsigned int uint32_t;
64 #define UINT32_C(x) x ## U
66 #elif LONG_MAX == 2147483647L
69 typedef signed long int32_t;
70 typedef unsigned long uint32_t;
73 #define INT32_C(x) x ## L
74 #define UINT32_C(x) x ## UL
78 #error "Neither int nor long is 32 bits in size"
82 /*** 16-bit size: int or short ***/
87 typedef signed int int16_t;
88 typedef unsigned int uint16_t;
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;
102 #define UINT16_C(x) x ## U
106 #error "Neither short nor int is 16 bits in size"
110 /*** 8-bit size: char ***/
115 typedef signed char int8_t;
116 typedef unsigned char uint8_t;
120 #define UINT8_C(x) x ## U
124 #error "char is not 8 bits in size"
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 */