File: h-type.h

package info (click to toggle)
zangband 1%3A2.7.5pre1-12
  • links: PTS
  • area: non-free
  • in suites:
  • size: 12,900 kB
  • sloc: ansic: 169,743; tcl: 20,729; makefile: 223; sh: 12
file content (168 lines) | stat: -rwxr-xr-x 4,102 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* File: h-type.h */

#ifndef INCLUDED_H_TYPE_H
#define INCLUDED_H_TYPE_H

/*
 * Basic "types".
 *
 * Note the attempt to make all basic types have 4 letters.
 * This improves readibility and standardizes the code.
 *
 * Likewise, all complex types are at least 4 letters.
 * Thus, almost every 1 to 3 letter word is a legal variable,
 * except for certain reserved words ('for' and 'if' and 'do').
 *
 * Note that the type used in structures for bit flags should be uint.
 * As long as these bit flags are sequential, they will be space smart.
 *
 * Note that on some machines, apparently "signed char" is illegal.
 *
 * A char/byte takes exactly 1 byte
 * A s16b/u16b takes exactly 2 bytes
 * A s32b/u32b takes exactly 4 bytes
 *
 * A sint/uint takes at least 2 bytes
 * A long/huge takes at least 4 bytes
 *
 * A real normally takes from 4 to 10 bytes
 * A vptr normally takes 4 (rarely 8) bytes
 *
 * Note that some files have already been included by "h-include.h"
 * These include <stdio.h> and <sys/types>, which define some types
 * In particular, "bool", "byte", "uint", and "huge" may be defined
 * already, possibly using "typedefs" of various kinds, and possibly
 * being defined to something other than required by my code.  So we
 * simply redefine them all using a stupid "_hack" suffix.
 *
 * Also, see <limits.h> for min/max values for sint, uint, long, huge
 * (INT_MIN, INT_MAX, 0, UINT_MAX, LONG_MIN, LONG_MAX, 0, ULONG_MAX).
 * These limits should be verified and coded into "h-constant.h", or
 * perhaps not, since those types have "unknown" length by definition.
 */



/*** Special 4 letter names for some standard types ***/


/* A generic pointer */
typedef void *vptr;


/*
 * Hack -- prevent problems with non-MACINTOSH
 */
#undef uint
#define uint uint_hack

/*
 * Hack -- prevent problems with MSDOS and WINDOWS
 */
#undef huge
#define huge huge_hack

/*
 * Hack -- prevent problems with AMIGA
 */
#undef byte
#define byte byte_hack

/*
 * Hack -- prevent problems with C++
 */
#undef bool
#define bool bool_hack


/* Note that "signed char" is not always "defined" */
/* So always use "s16b" to hold small signed values */
/* A signed byte of memory */
/* typedef signed char syte; */

/* Note that unsigned values can cause math problems */
/* An unsigned byte of memory */
typedef unsigned char byte;

/* Note that a bool is smaller than a full "int" */
/* Simple True/False type */
typedef char bool;


/* A signed, standard integer (at least 2 bytes) */
typedef int sint;

/* An unsigned, "standard" integer (often pre-defined) */
typedef unsigned int uint;

/* The largest possible unsigned integer */
typedef unsigned long huge;


/* Signed/Unsigned 16 bit value */
typedef signed short s16b;
typedef unsigned short u16b;

/* detect 64 bit GCC */
#ifdef _LP64
#ifndef L64
#define L64 1
#endif
#ifndef USE_64B
#define USE_64B 1
#endif
#endif

/* Signed/Unsigned 32 bit value */
#ifdef L64						/* 64 bit longs */
typedef signed int s32b;
typedef unsigned int u32b;

#ifdef USE_64B
/* Signed/Unsigned 64bit value */
typedef long u64b;
typedef unsigned long s64b;
#endif /* USE_64B */

#else  /* L64 */

typedef signed long s32b;
typedef unsigned long u32b;

#ifdef USE_64B

/* Try to get a 64 bit type */
# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
#  include <stdint.h>
#  define ANG_U64B uint64_t
#  define ANG_S64B int64_t
# endif	/* __STDC__ && __STDC_VERSION__ */

/* Define this for Microsoft Dev Studio C++ 6.0 */
# ifdef MSDEV
#  define ANG_U64B unsigned __int64
#  define ANG_S64B __int64
# endif	/* MSDEV */

/* Define this if you have <sys/types.h> with an old compiler */
# if defined HAS_SYS_TYPES && !defined ANG_U64B
#  include <sys/types.h>
#  define ANG_U64B u_int64_t
#  define ANG_S64B int64_t
# endif	/* HAS_SYS_TYPES */

/* Attempt to use "long long" which is semi-standard for older compilers */
# ifndef ANG_U64B
#  define ANG_U64B unsigned long long
#  define ANG_S64B long long
# endif	/* ANG_U64B */

/* Define the 64bit types */
typedef ANG_U64B u64b;
typedef ANG_S64B s64b;

#endif /* USE_64B */

#endif /* L64 */

#endif