TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sophist.h
Go to the documentation of this file.
1 /* sophist.h - 0.3 - public domain - Sean Barrett 2010
2 ** Knowledge drawn from Brian Hook's posh.h and http://predef.sourceforge.net
3 ** Sophist provides portable types; you typedef/#define them to your own names
4 **
5 ** defines:
6 ** - SOPHIST_endian - either SOPHIST_little_endian or SOPHIST_big_endian
7 ** - SOPHIST_has_64 - either 0 or 1; if 0, int64 types aren't defined
8 ** - SOPHIST_pointer64 - either 0 or 1; if 1, pointer is 64-bit
9 **
10 ** - SOPHIST_intptr, SOPHIST_uintptr - integer same size as pointer
11 ** - SOPHIST_int8, SOPHIST_uint8, SOPHIST_int16, SOPHIST_uint16
12 ** - SOPHIST_int32, SOPHIST_uint32, SOPHIST_int64, SOPHIST_uint64
13 ** - SOPHIST_int64_constant(number) - macros for creating 64-bit
14 ** - SOPHIST_uint64_constant(number) integer constants
15 ** - SOPHIST_printf_format64 - string for printf format for int64
16 */
17 
18 #ifndef __INCLUDE_SOPHIST_H__
19 #define __INCLUDE_SOPHIST_H__
20 
21 #define SOPHIST_compiletime_assert(name,val) \
22  typedef int SOPHIST__assert##name[(val) ? 1 : -1]
23 
24 /* define a couple synthetic rules to make code more readable */
25 #if (defined(__sparc__) || defined(__sparc)) && \
26  (defined(__arch64__) || defined(__sparcv9) || defined(__sparc_v9__))
27  #define SOPHIST_sparc64
28 #endif
29 
30 #if (defined(linux) || defined(__linux__)) && \
31  (defined(__alpha)||defined(__alpha__)||defined(__x86_64__)||defined(_M_X64))
32  #define SOPHIST_linux64
33 #endif
34 
35 /* basic types */
36 typedef signed char SOPHIST_int8;
37 typedef unsigned char SOPHIST_uint8;
38 
39 typedef signed short SOPHIST_int16;
40 typedef unsigned short SOPHIST_uint16;
41 
42 #ifdef __palmos__
43  typedef signed long SOPHIST_int32;
44  typedef unsigned long SOPHIST_uint32;
45 #else
46  typedef signed int SOPHIST_int32;
47  typedef unsigned int SOPHIST_uint32;
48 #endif
49 
50 #ifndef SOPHIST_NO_64
51  #if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) \
52  || (defined(__alpha) && defined(__DECC))
53 
54  typedef signed __int64 SOPHIST_int64;
55  typedef unsigned __int64 SOPHIST_uint64;
56  #define SOPHIST_has_64 1
57  #define SOPHIST_int64_constant(x) (x##i64)
58  #define SOPHIST_uint64_constant(x) (x##ui64)
59  #define SOPHIST_printf_format64 "I64"
60 
61  #elif defined(__LP64__) || defined(__powerpc64__) || defined(SOPHIST_sparc64)
62 
63  typedef signed long SOPHIST_int64;
64  typedef unsigned long SOPHIST_uint64;
65 
66  #define SOPHIST_has_64 1
67  #define SOPHIST_int64_constant(x) ((SOPHIST_int64) x)
68  #define SOPHIST_uint64_constant(x) ((SOPHIST_uint64) x)
69  #define SOPHIST_printf_format64 "l"
70 
71  #elif defined(_LONG_LONG) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) \
72  || defined(__GNUC__) || defined(__MWERKS__) || defined(__APPLE_CC__) \
73  || defined(sgi) || defined (__sgi) || defined(__sgi__) \
74  || defined(_CRAYC)
75 
76  typedef signed long long SOPHIST_int64;
77  typedef unsigned long long SOPHIST_uint64;
78 
79  #define SOPHIST_has_64 1
80  #define SOPHIST_int64_constant(x) (x##LL)
81  #define SOPHIST_uint64_constant(x) (x##ULL)
82  #define SOPHIST_printf_format64 "ll"
83  #endif
84 #endif
85 
86 #ifndef SOPHIST_has_64
87 #define SOPHIST_has_64 0
88 #endif
89 
94 
95 #if SOPHIST_has_64
96  SOPHIST_compiletime_assert( int64, sizeof(SOPHIST_int64 ) == 8);
97  SOPHIST_compiletime_assert(uint64, sizeof(SOPHIST_uint64) == 8);
98 #endif
99 
100 /* determine whether pointers are 64-bit */
101 
102 #if defined(SOPHIST_linux64) || defined(SOPHIST_sparc64) \
103  || defined(__osf__) || (defined(_WIN64) && !defined(_XBOX)) \
104  || defined(__64BIT__) \
105  || defined(__LP64) || defined(__LP64__) || defined(_LP64) \
106  || defined(_ADDR64) || defined(_CRAYC) \
107 
108  #define SOPHIST_pointer64 1
109 
110  SOPHIST_compiletime_assert(pointer64, sizeof(void*) == 8);
111 
112  typedef SOPHIST_int64 SOPHIST_intptr;
113  typedef SOPHIST_uint64 SOPHIST_uintptr;
114 #else
115 
116  #define SOPHIST_pointer64 0
117 
118  SOPHIST_compiletime_assert(pointer64, sizeof(void*) <= 4);
119 
120  /* do we care about pointers that are only 16-bit? */
123 
124 #endif
125 
126 SOPHIST_compiletime_assert(intptr, sizeof(SOPHIST_intptr) == sizeof(char *));
127 
128 /* enumerate known little endian cases; fallback to big-endian */
129 
130 #define SOPHIST_little_endian 1
131 #define SOPHIST_big_endian 2
132 
133 #if defined(__386__) || defined(i386) || defined(__i386__) \
134  || defined(__X86) || defined(_M_IX86) \
135  || defined(_M_X64) || defined(__x86_64__) \
136  || defined(alpha) || defined(__alpha) || defined(__alpha__) \
137  || defined(_M_ALPHA) \
138  || defined(ARM) || defined(_ARM) || defined(__arm__) \
139  || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
140  || defined(_WIN32_WCE) || defined(__NT__) \
141  || defined(__MIPSEL__)
142  #define SOPHIST_endian SOPHIST_little_endian
143 #else
144  #define SOPHIST_endian SOPHIST_big_endian
145 #endif
146 
147 #endif /* __INCLUDE_SOPHIST_H__ */
unsigned char SOPHIST_uint8
Definition: sophist.h:37
#define SOPHIST_compiletime_assert(name, val)
Definition: sophist.h:21
int8_t int8
Definition: Define.h:148
int64_t int64
Definition: Define.h:145
signed int SOPHIST_int32
Definition: sophist.h:46
SOPHIST_uint32 SOPHIST_uintptr
Definition: sophist.h:122
signed short SOPHIST_int16
Definition: sophist.h:39
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
uint16_t uint16
Definition: Define.h:151
unsigned int SOPHIST_uint32
Definition: sophist.h:47
signed char SOPHIST_int8
Definition: sophist.h:36
SOPHIST_int32 SOPHIST_intptr
Definition: sophist.h:121
unsigned short SOPHIST_uint16
Definition: sophist.h:40