OSDN Git Service

Bring over habu's 2012 November 18 change, autoconfから--enable-c99を削除し、stdint.hの有無で判定す...
[hengbandforosx/hengbandosx.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 #ifdef HAVE_STDINT_H
42 #include <stdint.h>
43 #endif
44
45 /*** Special 4 letter names for some standard types ***/
46
47
48 /* A standard pointer (to "void" because ANSI C says so) */
49 typedef void *vptr;
50
51 /* A simple pointer (to unmodifiable strings) */
52 typedef const char *cptr;
53
54
55 /* Since float's are silly, hard code real numbers as doubles */
56 typedef double real;
57
58
59 /* Error codes for function return values */
60 /* Success = 0, Failure = -N, Problem = +N */
61 typedef int errr;
62
63
64 /*
65  * Hack -- prevent problems with non-MACINTOSH
66  */
67 #undef uint
68 #define uint uint_hack
69
70 /*
71  * Hack -- prevent problems with MSDOS and WINDOWS
72  */
73 #undef huge
74 #define huge huge_hack
75
76 /*
77  * Hack -- prevent problems with AMIGA
78  */
79 #undef byte
80 #define byte byte_hack
81
82 /*
83  * Hack -- prevent problems with C++
84  */
85 #undef bool
86 #define bool bool_hack
87
88
89 /* Note that "signed char" is not always "defined" */
90 /* So always use "s16b" to hold small signed values */
91 /* A signed byte of memory */
92 /* typedef signed char syte; */
93
94 /* Note that unsigned values can cause math problems */
95 /* An unsigned byte of memory */
96 typedef unsigned char byte;
97
98 /* Note that a bool is smaller than a full "int" */
99 /* Simple True/False type */
100 typedef char bool;
101
102
103 /* A signed, standard integer (at least 2 bytes) */
104 typedef int sint;
105
106 /* An unsigned, "standard" integer (often pre-defined) */
107 typedef unsigned int uint;
108
109
110 /* The largest possible signed integer (pre-defined) */
111 /* typedef long long; */
112
113 /* The largest possible unsigned integer */
114 typedef unsigned long huge;
115
116
117 /* Signed/Unsigned 16 bit value */
118 #ifdef HAVE_STDINT_H
119 typedef int16_t s16b;
120 typedef uint16_t u16b;
121 #else
122 typedef signed short s16b;
123 typedef unsigned short u16b;
124 #endif
125
126 /* Signed/Unsigned 32 bit value */
127 #ifdef HAVE_STDINT_H
128 typedef int32_t s32b;
129 typedef uint32_t u32b;
130 #else
131 typedef signed long s32b;
132 typedef unsigned long u32b;
133 #endif
134
135
136
137
138 /*** Pointers to all the basic types defined above ***/
139
140 typedef real *real_ptr;
141 typedef errr *errr_ptr;
142 typedef char *char_ptr;
143 typedef byte *byte_ptr;
144 typedef bool *bool_ptr;
145 typedef sint *sint_ptr;
146 typedef uint *uint_ptr;
147 typedef long *long_ptr;
148 typedef huge *huge_ptr;
149 typedef s16b *s16b_ptr;
150 typedef u16b *u16b_ptr;
151 typedef s32b *s32b_ptr;
152 typedef u32b *u32b_ptr;
153 typedef vptr *vptr_ptr;
154 typedef cptr *cptr_ptr;
155
156
157
158 /*** Pointers to Functions of special types (for various purposes) ***/
159
160 /* A generic function takes a user data and a special data */
161 typedef errr    (*func_gen)(vptr, vptr);
162
163 /* An equality testing function takes two things to compare (bool) */
164 typedef bool    (*func_eql)(vptr, vptr);
165
166 /* A comparison function takes two things and to compare (-1,0,+1) */
167 typedef sint    (*func_cmp)(vptr, vptr);
168
169 /* A hasher takes a thing (and a max hash size) to hash (0 to siz - 1) */
170 typedef uint    (*func_hsh)(vptr, uint);
171
172 /* A key extractor takes a thing and returns (a pointer to) some key */
173 typedef vptr    (*func_key)(vptr);
174
175
176
177 #endif
178