1 | #ifndef _CBASETYPES_H_ |
---|
2 | #define _CBASETYPES_H_ |
---|
3 | |
---|
4 | /* +--------+-----------+--------+---------+ |
---|
5 | * | ILP32 | LP64 | ILP64 | (LL)P64 | |
---|
6 | * +------------+--------+-----------+--------+---------+ |
---|
7 | * | ints | 32-bit | 32-bit | 64-bit | 32-bit | |
---|
8 | * | longs | 32-bit | 64-bit | 64-bit | 32-bit | |
---|
9 | * | long-longs | 64-bit | 64-bit | 64-bit | 64-bit | |
---|
10 | * | pointers | 32-bit | 64-bit | 64-bit | 64-bit | |
---|
11 | * +------------+--------+-----------+--------+---------+ |
---|
12 | * | where | -- | Tiger | Alpha | Windows | |
---|
13 | * | used | | Unix | Cray | | |
---|
14 | * | | | Sun & SGI | | | |
---|
15 | * +------------+--------+-----------+--------+---------+ |
---|
16 | * Taken from http://developer.apple.com/macosx/64bit.html |
---|
17 | */ |
---|
18 | |
---|
19 | ////////////////////////////////////////////////////////////////////////// |
---|
20 | // basic include for all basics |
---|
21 | // introduces types and global functions |
---|
22 | ////////////////////////////////////////////////////////////////////////// |
---|
23 | |
---|
24 | |
---|
25 | ////////////////////////////////////////////////////////////////////////// |
---|
26 | // setting some defines on platforms |
---|
27 | ////////////////////////////////////////////////////////////////////////// |
---|
28 | #if (defined(__WIN32__) || defined(__WIN32) || defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(WIN32) |
---|
29 | #define WIN32 |
---|
30 | #endif |
---|
31 | |
---|
32 | #if defined(__MINGW32__) && !defined(MINGW) |
---|
33 | #define MINGW |
---|
34 | #endif |
---|
35 | |
---|
36 | #if (defined(__CYGWIN__) || defined(__CYGWIN32__)) && !defined(CYGWIN) |
---|
37 | #define CYGWIN |
---|
38 | #endif |
---|
39 | |
---|
40 | // __APPLE__ is the only predefined macro on MacOS X |
---|
41 | #if defined(__APPLE__) |
---|
42 | #define __DARWIN__ |
---|
43 | #endif |
---|
44 | |
---|
45 | // 64bit OS |
---|
46 | #if defined(_M_IA64) || defined(_M_X64) || defined(_WIN64) || defined(_LP64) || defined(_ILP64) || defined(__LP64__) || defined(__ppc64__) |
---|
47 | #define __64BIT__ |
---|
48 | #endif |
---|
49 | |
---|
50 | #if defined(_ILP64) |
---|
51 | #error "this specific 64bit architecture is not supported" |
---|
52 | #endif |
---|
53 | |
---|
54 | // debug mode |
---|
55 | #if defined(_DEBUG) && !defined(DEBUG) |
---|
56 | #define DEBUG |
---|
57 | #endif |
---|
58 | |
---|
59 | // debug function name |
---|
60 | #ifndef __NETBSD__ |
---|
61 | #if __STDC_VERSION__ < 199901L |
---|
62 | # if __GNUC__ >= 2 |
---|
63 | # define __func__ __FUNCTION__ |
---|
64 | # else |
---|
65 | # define __func__ "" |
---|
66 | # endif |
---|
67 | #endif |
---|
68 | #endif |
---|
69 | |
---|
70 | |
---|
71 | // disable attributed stuff on non-GNU |
---|
72 | #if !defined(__GNUC__) && !defined(MINGW) |
---|
73 | # define __attribute__(x) |
---|
74 | #endif |
---|
75 | |
---|
76 | |
---|
77 | ////////////////////////////////////////////////////////////////////////// |
---|
78 | // typedefs to compensate type size change from 32bit to 64bit |
---|
79 | // MS implements LLP64 model, normal unix does LP64, |
---|
80 | // only Silicon Graphics/Cray goes ILP64 so don't care (and don't support) |
---|
81 | ////////////////////////////////////////////////////////////////////////// |
---|
82 | |
---|
83 | #include <limits.h> |
---|
84 | // ILP64 isn't supported, so always 32 bits? |
---|
85 | #ifndef UINT_MAX |
---|
86 | #define UINT_MAX 0xffffffff |
---|
87 | #endif |
---|
88 | |
---|
89 | ////////////////////////////////////////////////////////////////////////// |
---|
90 | // Integers with guaranteed _exact_ size. |
---|
91 | ////////////////////////////////////////////////////////////////////////// |
---|
92 | |
---|
93 | #define SIZEOF_LONG 4 |
---|
94 | #define SIZEOF_INT 4 |
---|
95 | #define HAVE_INT_8_16_32 |
---|
96 | |
---|
97 | typedef char int8; |
---|
98 | typedef short int16; |
---|
99 | typedef int int32; |
---|
100 | |
---|
101 | typedef signed char sint8; |
---|
102 | typedef signed short sint16; |
---|
103 | typedef signed int sint32; |
---|
104 | |
---|
105 | typedef unsigned char uint8; |
---|
106 | typedef unsigned short uint16; |
---|
107 | typedef unsigned int uint32; |
---|
108 | |
---|
109 | #undef UINT8_MIN |
---|
110 | #undef UINT16_MIN |
---|
111 | #undef UINT32_MIN |
---|
112 | #define UINT8_MIN ((uint8) 0) |
---|
113 | #define UINT16_MIN ((uint16)0) |
---|
114 | #define UINT32_MIN ((uint32)0) |
---|
115 | |
---|
116 | #undef UINT8_MAX |
---|
117 | #undef UINT16_MAX |
---|
118 | #undef UINT32_MAX |
---|
119 | #define UINT8_MAX ((uint8) 0xFF) |
---|
120 | #define UINT16_MAX ((uint16)0xFFFF) |
---|
121 | #define UINT32_MAX ((uint32)0xFFFFFFFF) |
---|
122 | |
---|
123 | #undef SINT8_MIN |
---|
124 | #undef SINT16_MIN |
---|
125 | #undef SINT32_MIN |
---|
126 | #define SINT8_MIN ((sint8) 0x80) |
---|
127 | #define SINT16_MIN ((sint16)0x8000) |
---|
128 | #define SINT32_MIN ((sint32)0x80000000) |
---|
129 | |
---|
130 | #undef SINT8_MAX |
---|
131 | #undef SINT16_MAX |
---|
132 | #undef SINT32_MAX |
---|
133 | #define SINT8_MAX ((sint8) 0x7F) |
---|
134 | #define SINT16_MAX ((sint16)0x7FFF) |
---|
135 | #define SINT32_MAX ((sint32)0x7FFFFFFF) |
---|
136 | |
---|
137 | ////////////////////////////////////////////////////////////////////////// |
---|
138 | // Integers with guaranteed _minimum_ size. |
---|
139 | // These could be larger than you expect, |
---|
140 | // they are designed for speed. |
---|
141 | ////////////////////////////////////////////////////////////////////////// |
---|
142 | typedef long int ppint; |
---|
143 | typedef long int ppint8; |
---|
144 | typedef long int ppint16; |
---|
145 | typedef long int ppint32; |
---|
146 | |
---|
147 | typedef unsigned long int ppuint; |
---|
148 | typedef unsigned long int ppuint8; |
---|
149 | typedef unsigned long int ppuint16; |
---|
150 | typedef unsigned long int ppuint32; |
---|
151 | |
---|
152 | |
---|
153 | ////////////////////////////////////////////////////////////////////////// |
---|
154 | // integer with exact processor width (and best speed) |
---|
155 | ////////////////////////////// |
---|
156 | #include <stddef.h> // size_t |
---|
157 | |
---|
158 | #if defined(WIN32) && !defined(MINGW) // does not have a signed size_t |
---|
159 | ////////////////////////////// |
---|
160 | #if defined(_WIN64) // naive 64bit windows platform |
---|
161 | typedef __int64 ssize_t; |
---|
162 | #else |
---|
163 | typedef int ssize_t; |
---|
164 | #endif |
---|
165 | ////////////////////////////// |
---|
166 | #endif |
---|
167 | ////////////////////////////// |
---|
168 | |
---|
169 | |
---|
170 | ////////////////////////////////////////////////////////////////////////// |
---|
171 | // portable 64-bit integers |
---|
172 | ////////////////////////////////////////////////////////////////////////// |
---|
173 | #if defined(_MSC_VER) || defined(__BORLANDC__) |
---|
174 | typedef __int64 int64; |
---|
175 | typedef signed __int64 sint64; |
---|
176 | typedef unsigned __int64 uint64; |
---|
177 | #define LLCONST(a) (a##i64) |
---|
178 | #else |
---|
179 | typedef long long int64; |
---|
180 | typedef signed long long sint64; |
---|
181 | typedef unsigned long long uint64; |
---|
182 | #define LLCONST(a) (a##ll) |
---|
183 | #endif |
---|
184 | |
---|
185 | #ifndef INT64_MIN |
---|
186 | #define INT64_MIN (LLCONST(-9223372036854775807)-1) |
---|
187 | #endif |
---|
188 | #ifndef INT64_MAX |
---|
189 | #define INT64_MAX (LLCONST(9223372036854775807)) |
---|
190 | #endif |
---|
191 | #ifndef UINT64_MAX |
---|
192 | #define UINT64_MAX (LLCONST(18446744073709551615u)) |
---|
193 | #endif |
---|
194 | |
---|
195 | |
---|
196 | ////////////////////////////////////////////////////////////////////////// |
---|
197 | // pointer sized integers |
---|
198 | ////////////////////////////////////////////////////////////////////////// |
---|
199 | #ifdef __64BIT__ |
---|
200 | typedef uint64 uintptr; |
---|
201 | typedef int64 intptr; |
---|
202 | #else |
---|
203 | typedef uint32 uintptr; |
---|
204 | typedef int32 intptr; |
---|
205 | #endif |
---|
206 | |
---|
207 | |
---|
208 | ////////////////////////////////////////////////////////////////////////// |
---|
209 | // some redefine of function redefines for some Compilers |
---|
210 | ////////////////////////////////////////////////////////////////////////// |
---|
211 | #if defined(_MSC_VER) || defined(__BORLANDC__) |
---|
212 | #define strcasecmp stricmp |
---|
213 | #define strncasecmp strnicmp |
---|
214 | #define strncmpi strnicmp |
---|
215 | #define snprintf _snprintf |
---|
216 | #if defined(_MSC_VER) && _MSC_VER < 1400 |
---|
217 | #define vsnprintf _vsnprintf |
---|
218 | #endif |
---|
219 | #else |
---|
220 | #define strcmpi strcasecmp |
---|
221 | #define stricmp strcasecmp |
---|
222 | #define strncmpi strncasecmp |
---|
223 | #define strnicmp strncasecmp |
---|
224 | #endif |
---|
225 | |
---|
226 | // keyword replacement in windows |
---|
227 | #ifdef _WIN32 |
---|
228 | #define inline __inline |
---|
229 | #endif |
---|
230 | |
---|
231 | ///////////////////////////// |
---|
232 | // for those still not building c++ |
---|
233 | #ifndef __cplusplus |
---|
234 | ////////////////////////////// |
---|
235 | |
---|
236 | // boolean types for C |
---|
237 | typedef char bool; |
---|
238 | #define false (1==0) |
---|
239 | #define true (1==1) |
---|
240 | |
---|
241 | ////////////////////////////// |
---|
242 | #endif // not cplusplus |
---|
243 | ////////////////////////////// |
---|
244 | |
---|
245 | ////////////////////////////////////////////////////////////////////////// |
---|
246 | // macro tools |
---|
247 | |
---|
248 | #ifdef swap // just to be sure |
---|
249 | #undef swap |
---|
250 | #endif |
---|
251 | // hmm only ints? |
---|
252 | //#define swap(a,b) { int temp=a; a=b; b=temp;} |
---|
253 | // if using macros then something that is type independent |
---|
254 | //#define swap(a,b) ((a == b) || ((a ^= b), (b ^= a), (a ^= b))) |
---|
255 | // Avoid "value computed is not used" warning and generates the same assembly code |
---|
256 | #define swap(a,b) if (a != b) ((a ^= b), (b ^= a), (a ^= b)) |
---|
257 | |
---|
258 | #ifndef max |
---|
259 | #define max(a,b) (((a) > (b)) ? (a) : (b)) |
---|
260 | #endif |
---|
261 | |
---|
262 | #ifndef min |
---|
263 | #define min(a,b) (((a) < (b)) ? (a) : (b)) |
---|
264 | #endif |
---|
265 | |
---|
266 | ////////////////////////////////////////////////////////////////////////// |
---|
267 | // should not happen |
---|
268 | #ifndef NULL |
---|
269 | #define NULL (void *)0 |
---|
270 | #endif |
---|
271 | |
---|
272 | ////////////////////////////////////////////////////////////////////////// |
---|
273 | // number of bits in a byte |
---|
274 | #ifndef NBBY |
---|
275 | #define NBBY 8 |
---|
276 | #endif |
---|
277 | |
---|
278 | ////////////////////////////////////////////////////////////////////////// |
---|
279 | // path separator |
---|
280 | |
---|
281 | #if defined(WIN32) |
---|
282 | #define PATHSEP '\\' |
---|
283 | #elif defined(__APPLE__) |
---|
284 | #define PATHSEP ':' |
---|
285 | #else |
---|
286 | #define PATHSEP '/' |
---|
287 | #endif |
---|
288 | |
---|
289 | ////////////////////////////////////////////////////////////////////////// |
---|
290 | // Assert |
---|
291 | |
---|
292 | #if ! defined(Assert) |
---|
293 | #if defined(RELEASE) |
---|
294 | #define Assert(EX) |
---|
295 | #else |
---|
296 | // extern "C" { |
---|
297 | #include <assert.h> |
---|
298 | // } |
---|
299 | #if !defined(DEFCPP) && defined(WIN32) && !defined(MINGW) |
---|
300 | #include <crtdbg.h> |
---|
301 | #endif |
---|
302 | #define Assert(EX) assert(EX) |
---|
303 | #endif |
---|
304 | #endif /* ! defined(Assert) */ |
---|
305 | |
---|
306 | ////////////////////////////////////////////////////////////////////////// |
---|
307 | // Has to be unsigned to avoid problems in some systems |
---|
308 | // Problems arise when these functions expect an argument in the range [0,256[ and are fed a signed char. |
---|
309 | #include <ctype.h> |
---|
310 | #define ISALNUM(c) (isalnum((unsigned char)(c))) |
---|
311 | #define ISALPHA(c) (isalpha((unsigned char)(c))) |
---|
312 | #define ISCNTRL(c) (iscntrl((unsigned char)(c))) |
---|
313 | #define ISDIGIT(c) (isdigit((unsigned char)(c))) |
---|
314 | #define ISGRAPH(c) (isgraph((unsigned char)(c))) |
---|
315 | #define ISLOWER(c) (islower((unsigned char)(c))) |
---|
316 | #define ISPRINT(c) (isprint((unsigned char)(c))) |
---|
317 | #define ISPUNCT(c) (ispunct((unsigned char)(c))) |
---|
318 | #define ISSPACE(c) (isspace((unsigned char)(c))) |
---|
319 | #define ISUPPER(c) (isupper((unsigned char)(c))) |
---|
320 | #define ISXDIGIT(c) (isxdigit((unsigned char)(c))) |
---|
321 | #define TOASCII(c) (toascii((unsigned char)(c))) |
---|
322 | #define TOLOWER(c) (tolower((unsigned char)(c))) |
---|
323 | #define TOUPPER(c) (toupper((unsigned char)(c))) |
---|
324 | |
---|
325 | ////////////////////////////////////////////////////////////////////////// |
---|
326 | // length of a static array |
---|
327 | #define ARRAYLENGTH(A) ( sizeof(A)/sizeof((A)[0]) ) |
---|
328 | |
---|
329 | ////////////////////////////////////////////////////////////////////////// |
---|
330 | // Make sure va_copy exists |
---|
331 | #include <stdarg.h> // va_list, va_copy(?) |
---|
332 | #if !defined(va_copy) |
---|
333 | #if defined(__va_copy) |
---|
334 | #define va_copy __va_copy |
---|
335 | #else |
---|
336 | #define va_copy(dst, src) ((void) memcpy(&(dst), &(src), sizeof(va_list))) |
---|
337 | #endif |
---|
338 | #endif |
---|
339 | |
---|
340 | #endif /* _CBASETYPES_H_ */ |
---|