OSDN Git Service

先のコミットだとC99に完全対応していないコンパイラが対応できないので、プリプロセッサ「C99」で囲って以前のtypedef宣言も差し戻した。
[hengband/hengband.git] / src / h-type.h
1 /* File: h-type.h */
2
3 #ifdef C99
4 #include <stdint.h>
5 #endif
6
7 #ifndef INCLUDED_H_TYPE_H
8 #define INCLUDED_H_TYPE_H
9
10 /*
11  * Basic "types".
12  *
13  * Note the attempt to make all basic types have 4 letters.
14  * This improves readibility and standardizes the code.
15  *
16  * Likewise, all complex types are at least 4 letters.
17  * Thus, almost every three letter word is a legal variable.
18  * But beware of certain reserved words ('for' and 'if' and 'do').
19  *
20  * Note that the type used in structures for bit flags should be uint.
21  * As long as these bit flags are sequential, they will be space smart.
22  *
23  * Note that on some machines, apparently "signed char" is illegal.
24  *
25  * It must be true that char/byte takes exactly 1 byte
26  * It must be true that sind/uind takes exactly 2 bytes
27  * It must be true that sbig/ubig takes exactly 4 bytes
28  *
29  * On Sparc's, a sint takes 4 bytes (2 is legal)
30  * On Sparc's, a uint takes 4 bytes (2 is legal)
31  * On Sparc's, a long takes 4 bytes (8 is legal)
32  * On Sparc's, a huge takes 4 bytes (8 is legal)
33  * On Sparc's, a vptr takes 4 bytes (8 is legal)
34  * On Sparc's, a real takes 8 bytes (4 is legal)
35  *
36  * Note that some files have already been included by "h-include.h"
37  * These include <stdio.h> and <sys/types>, which define some types
38  * In particular, uint is defined so we do not have to define it
39  *
40  * Also, see <limits.h> for min/max values for sind, uind, long, huge
41  * (SHRT_MIN, SHRT_MAX, USHRT_MAX, LONG_MIN, LONG_MAX, ULONG_MAX)
42  * These limits should be verified and coded into "h-constant.h".
43  */
44
45
46
47 /*** Special 4 letter names for some standard types ***/
48
49
50 /* A standard pointer (to "void" because ANSI C says so) */
51 typedef void *vptr;
52
53 /* A simple pointer (to unmodifiable strings) */
54 typedef const char *cptr;
55
56
57 /* Since float's are silly, hard code real numbers as doubles */
58 typedef double real;
59
60
61 /* Error codes for function return values */
62 /* Success = 0, Failure = -N, Problem = +N */
63 typedef int errr;
64
65
66 /*
67  * Hack -- prevent problems with non-MACINTOSH
68  */
69 #undef uint
70 #define uint uint_hack
71
72 /*
73  * Hack -- prevent problems with MSDOS and WINDOWS
74  */
75 #undef huge
76 #define huge huge_hack
77
78 /*
79  * Hack -- prevent problems with AMIGA
80  */
81 #undef byte
82 #define byte byte_hack
83
84 /*
85  * Hack -- prevent problems with C++
86  */
87 #undef bool
88 #define bool bool_hack
89
90
91 /* Note that "signed char" is not always "defined" */
92 /* So always use "s16b" to hold small signed values */
93 /* A signed byte of memory */
94 /* typedef signed char syte; */
95
96 /* Note that unsigned values can cause math problems */
97 /* An unsigned byte of memory */
98 typedef unsigned char byte;
99
100 /* Note that a bool is smaller than a full "int" */
101 /* Simple True/False type */
102 typedef char bool;
103
104
105 /* A signed, standard integer (at least 2 bytes) */
106 typedef int sint;
107
108 /* An unsigned, "standard" integer (often pre-defined) */
109 typedef unsigned int uint;
110
111
112 /* The largest possible signed integer (pre-defined) */
113 /* typedef long long; */
114
115 /* The largest possible unsigned integer */
116 typedef unsigned long huge;
117
118
119 /* Signed/Unsigned 16 bit value */
120 #ifdef C99
121 typedef int16_t s16b;
122 typedef uint16_t u16b;
123 #else
124 typedef signed short s16b;
125 typedef unsigned short u16b;
126 #endif
127
128 /* Signed/Unsigned 32 bit value */
129 #ifdef C99
130
131 #ifdef L64 /* 64 bit longs */
132 typedef signed int s32b;
133 typedef unsigned int u32b;
134 #else
135 typedef signed long s32b;
136 typedef unsigned long u32b;
137 #endif
138
139 #else
140 typedef signed long s32b;
141 typedef unsigned long u32b;
142 #endif
143
144
145
146
147 /*** Pointers to all the basic types defined above ***/
148
149 typedef real *real_ptr;
150 typedef errr *errr_ptr;
151 typedef char *char_ptr;
152 typedef byte *byte_ptr;
153 typedef bool *bool_ptr;
154 typedef sint *sint_ptr;
155 typedef uint *uint_ptr;
156 typedef long *long_ptr;
157 typedef huge *huge_ptr;
158 typedef s16b *s16b_ptr;
159 typedef u16b *u16b_ptr;
160 typedef s32b *s32b_ptr;
161 typedef u32b *u32b_ptr;
162 typedef vptr *vptr_ptr;
163 typedef cptr *cptr_ptr;
164
165
166
167 /*** Pointers to Functions of special types (for various purposes) ***/
168
169 /* A generic function takes a user data and a special data */
170 typedef errr    (*func_gen)(vptr, vptr);
171
172 /* An equality testing function takes two things to compare (bool) */
173 typedef bool    (*func_eql)(vptr, vptr);
174
175 /* A comparison function takes two things and to compare (-1,0,+1) */
176 typedef sint    (*func_cmp)(vptr, vptr);
177
178 /* A hasher takes a thing (and a max hash size) to hash (0 to siz - 1) */
179 typedef uint    (*func_hsh)(vptr, uint);
180
181 /* A key extractor takes a thing and returns (a pointer to) some key */
182 typedef vptr    (*func_key)(vptr);
183
184
185
186 #endif
187