OSDN Git Service

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