1/****************************************************************************
2 *
3 * config/integer-types.h
4 *
5 * FreeType integer types definitions.
6 *
7 * Copyright (C) 1996-2025 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
9 *
10 * This file is part of the FreeType project, and may only be used,
11 * modified, and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
15 *
16 */
17#ifndef FREETYPE_CONFIG_INTEGER_TYPES_H_
18#define FREETYPE_CONFIG_INTEGER_TYPES_H_
19
20FT_BEGIN_HEADER
21
22 /* There are systems (like the Texas Instruments 'C54x) where a `char` */
23 /* has 16~bits. ANSI~C says that `sizeof(char)` is always~1. Since an */
24 /* `int` has 16~bits also for this system, `sizeof(int)` gives~1 which */
25 /* is probably unexpected. */
26 /* */
27 /* `CHAR_BIT` (defined in `limits.h`) gives the number of bits in a */
28 /* `char` type. */
29
30#ifndef FT_CHAR_BIT
31#define FT_CHAR_BIT CHAR_BIT
32#endif
33
34#ifndef FT_SIZEOF_INT
35
36 /* The size of an `int` type. */
37#if FT_UINT_MAX == 0xFFFFUL
38#define FT_SIZEOF_INT ( 16 / FT_CHAR_BIT )
39#elif FT_UINT_MAX == 0xFFFFFFFFUL
40#define FT_SIZEOF_INT ( 32 / FT_CHAR_BIT )
41#elif FT_UINT_MAX > 0xFFFFFFFFUL && FT_UINT_MAX == 0xFFFFFFFFFFFFFFFFUL
42#define FT_SIZEOF_INT ( 64 / FT_CHAR_BIT )
43#else
44#error "Unsupported size of `int' type!"
45#endif
46
47#endif /* !defined(FT_SIZEOF_INT) */
48
49#ifndef FT_SIZEOF_LONG
50
51 /* The size of a `long` type. A five-byte `long` (as used e.g. on the */
52 /* DM642) is recognized but avoided. */
53#if FT_ULONG_MAX == 0xFFFFFFFFUL
54#define FT_SIZEOF_LONG ( 32 / FT_CHAR_BIT )
55#elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFUL
56#define FT_SIZEOF_LONG ( 32 / FT_CHAR_BIT )
57#elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFFFFFFFUL
58#define FT_SIZEOF_LONG ( 64 / FT_CHAR_BIT )
59#else
60#error "Unsupported size of `long' type!"
61#endif
62
63#endif /* !defined(FT_SIZEOF_LONG) */
64
65#ifndef FT_SIZEOF_LONG_LONG
66
67 /* The size of a `long long` type if available */
68#if defined( FT_ULLONG_MAX ) && FT_ULLONG_MAX >= 0xFFFFFFFFFFFFFFFFULL
69#define FT_SIZEOF_LONG_LONG ( 64 / FT_CHAR_BIT )
70#else
71#define FT_SIZEOF_LONG_LONG 0
72#endif
73
74#endif /* !defined(FT_SIZEOF_LONG_LONG) */
75
76
77 /**************************************************************************
78 *
79 * @section:
80 * basic_types
81 *
82 */
83
84
85 /**************************************************************************
86 *
87 * @type:
88 * FT_Int16
89 *
90 * @description:
91 * A typedef for a 16bit signed integer type.
92 */
93 typedef signed short FT_Int16;
94
95
96 /**************************************************************************
97 *
98 * @type:
99 * FT_UInt16
100 *
101 * @description:
102 * A typedef for a 16bit unsigned integer type.
103 */
104 typedef unsigned short FT_UInt16;
105
106 /* */
107
108
109 /* this #if 0 ... #endif clause is for documentation purposes */
110#if 0
111
112 /**************************************************************************
113 *
114 * @type:
115 * FT_Int32
116 *
117 * @description:
118 * A typedef for a 32bit signed integer type. The size depends on the
119 * configuration.
120 */
121 typedef signed XXX FT_Int32;
122
123
124 /**************************************************************************
125 *
126 * @type:
127 * FT_UInt32
128 *
129 * A typedef for a 32bit unsigned integer type. The size depends on the
130 * configuration.
131 */
132 typedef unsigned XXX FT_UInt32;
133
134
135 /**************************************************************************
136 *
137 * @type:
138 * FT_Int64
139 *
140 * A typedef for a 64bit signed integer type. The size depends on the
141 * configuration. Only defined if there is real 64bit support;
142 * otherwise, it gets emulated with a structure (if necessary).
143 */
144 typedef signed XXX FT_Int64;
145
146
147 /**************************************************************************
148 *
149 * @type:
150 * FT_UInt64
151 *
152 * A typedef for a 64bit unsigned integer type. The size depends on the
153 * configuration. Only defined if there is real 64bit support;
154 * otherwise, it gets emulated with a structure (if necessary).
155 */
156 typedef unsigned XXX FT_UInt64;
157
158 /* */
159
160#endif
161
162#if FT_SIZEOF_INT == ( 32 / FT_CHAR_BIT )
163
164 typedef signed int FT_Int32;
165 typedef unsigned int FT_UInt32;
166
167#elif FT_SIZEOF_LONG == ( 32 / FT_CHAR_BIT )
168
169 typedef signed long FT_Int32;
170 typedef unsigned long FT_UInt32;
171
172#else
173#error "no 32bit type found -- please check your configuration files"
174#endif
175
176
177 /* look up an integer type that is at least 32~bits */
178#if FT_SIZEOF_INT >= ( 32 / FT_CHAR_BIT )
179
180 typedef int FT_Fast;
181 typedef unsigned int FT_UFast;
182
183#elif FT_SIZEOF_LONG >= ( 32 / FT_CHAR_BIT )
184
185 typedef long FT_Fast;
186 typedef unsigned long FT_UFast;
187
188#endif
189
190
191 /* determine whether we have a 64-bit integer type */
192#if FT_SIZEOF_LONG == ( 64 / FT_CHAR_BIT )
193
194#define FT_INT64 long
195#define FT_UINT64 unsigned long
196
197#elif FT_SIZEOF_LONG_LONG >= ( 64 / FT_CHAR_BIT )
198
199#define FT_INT64 long long int
200#define FT_UINT64 unsigned long long int
201
202 /**************************************************************************
203 *
204 * A 64-bit data type may create compilation problems if you compile in
205 * strict ANSI mode. To avoid them, we disable other 64-bit data types if
206 * `__STDC__` is defined. You can however ignore this rule by defining the
207 * `FT_CONFIG_OPTION_FORCE_INT64` configuration macro.
208 */
209#elif !defined( __STDC__ ) || defined( FT_CONFIG_OPTION_FORCE_INT64 )
210
211#if defined( _MSC_VER ) && _MSC_VER >= 900 /* Visual C++ (and Intel C++) */
212
213 /* this compiler provides the `__int64` type */
214#define FT_INT64 __int64
215#define FT_UINT64 unsigned __int64
216
217#elif defined( __BORLANDC__ ) /* Borland C++ */
218
219 /* XXXX: We should probably check the value of `__BORLANDC__` in order */
220 /* to test the compiler version. */
221
222 /* this compiler provides the `__int64` type */
223#define FT_INT64 __int64
224#define FT_UINT64 unsigned __int64
225
226#elif defined( __WATCOMC__ ) && __WATCOMC__ >= 1100 /* Watcom C++ */
227
228#define FT_INT64 long long int
229#define FT_UINT64 unsigned long long int
230
231#elif defined( __MWERKS__ ) /* Metrowerks CodeWarrior */
232
233#define FT_INT64 long long int
234#define FT_UINT64 unsigned long long int
235
236#elif defined( __GNUC__ )
237
238 /* GCC provides the `long long` type */
239#define FT_INT64 long long int
240#define FT_UINT64 unsigned long long int
241
242#endif /* !__STDC__ */
243
244#endif /* FT_SIZEOF_LONG == (64 / FT_CHAR_BIT) */
245
246#ifdef FT_INT64
247
248 typedef FT_INT64 FT_Int64;
249 typedef FT_UINT64 FT_UInt64;
250
251# define FT_INT64_ZERO 0
252
253#else /* !FT_INT64 */
254
255 /* we need to emulate 64-bit data types if none are available */
256
257 typedef struct FT_Int64_
258 {
259 FT_UInt32 lo;
260 FT_UInt32 hi;
261
262 } FT_Int64;
263
264 typedef struct FT_UInt64_
265 {
266 FT_UInt32 lo;
267 FT_UInt32 hi;
268
269 } FT_UInt64;
270
271# define FT_INT64_ZERO { 0, 0 }
272
273#endif /* !FT_INT64 */
274
275FT_END_HEADER
276
277#endif /* FREETYPE_CONFIG_INTEGER_TYPES_H_ */
278