Skip to content

Commit 2dc8abc

Browse files
Add ctypes.inc
1 parent 71a8d0a commit 2dc8abc

File tree

1 file changed

+196
-0
lines changed

1 file changed

+196
-0
lines changed

units/ctypes.inc

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
// C data types
2+
3+
{
4+
Simple DirectMedia Layer
5+
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
6+
7+
Pascal-Header-Conversion
8+
Copyright (C) 2012-2020 Tim Blume aka End/EV1313
9+
10+
SDL2-for-Pascal
11+
Copyright (C) 2020-2021 PGD Community
12+
13+
This file is part of the project above. It has solely the purpose
14+
to map common C data types correctly by Pascal compilers.
15+
16+
FPC: Most C data types are found in the native ctypes unit.
17+
Delphi + others: Relies on this file for C data type mapping.
18+
19+
These native C types should be strictly separated from
20+
types defined by SDL which can be found in sdlstdinc.inc.
21+
}
22+
23+
{$IFNDEF FPC}
24+
type
25+
DWord = LongWord;
26+
27+
ppcbool = ^pcbool;
28+
pcbool = ^cbool;
29+
cbool = LongBool;
30+
{$EXTERNALSYM cbool}
31+
32+
ppcint8 = ^pcint8;
33+
pcint8 = ^cint8;
34+
cint8 = ShortInt;
35+
{$EXTERNALSYM cint8}
36+
37+
pcuint8 = ^cuint8;
38+
cuint8 = Byte;
39+
{$EXTERNALSYM cuint8}
40+
41+
ppcint16 = ^pcint16;
42+
pcint16 = ^cint16;
43+
cint16 = SmallInt;
44+
{$EXTERNALSYM cint16}
45+
46+
ppcuint16 = ^pcuint16;
47+
pcuint16 = ^cuint16;
48+
cuint16 = Word;
49+
{$EXTERNALSYM cuint16}
50+
51+
ppcushort = ^pcushort;
52+
pcushort = ^cushort;
53+
cushort = Word;
54+
{$EXTERNALSYM cushort}
55+
56+
ppcint32 = ^pcint32;
57+
pcint32 = ^cint32;
58+
cint32 = LongInt;
59+
{$EXTERNALSYM cint32}
60+
61+
ppcuint32 = ^pcuint32;
62+
pcuint32 = ^cuint32;
63+
cuint32 = LongWord;
64+
{$EXTERNALSYM cuint32}
65+
66+
{$IFNDEF Has_Int64}
67+
ppcint64 = ^pcint64;
68+
pcint64 = ^cint64;
69+
cint64 = record
70+
hi: cuint32;
71+
lo: cuint32;
72+
end;
73+
{$EXTERNALSYM cint64}
74+
75+
ppcuint64 = ^pcuint64;
76+
pcuint64 = ^cuint64;
77+
cuint64 = record
78+
hi: cuint32;
79+
lo: cuint32;
80+
end;
81+
{$EXTERNALSYM cuint64}
82+
{$ELSE}
83+
ppcint64 = ^pcint64;
84+
pcint64 = ^cint64;
85+
cint64 = Int64;
86+
{$EXTERNALSYM cint64}
87+
88+
ppcuint64 = ^pcuint64;
89+
pcuint64 = ^cuint64;
90+
cuint64 = UInt64;
91+
{$EXTERNALSYM cuint64}
92+
{$ENDIF}
93+
94+
ppcsize_t = ^pcsize_t;
95+
pcsize_t = ^csize_t;
96+
{$IFNDEF WIN64}
97+
csize_t = cuint32;
98+
{$ELSE}
99+
csize_t = cuint64;
100+
{$ENDIF}
101+
{$EXTERNALSYM csize_t}
102+
103+
ppcfloat = ^pcfloat;
104+
pcfloat = ^cfloat;
105+
cfloat = Single;
106+
{$EXTERNALSYM cfloat}
107+
108+
ppcdouble = ^pcdouble;
109+
pcdouble = ^cdouble;
110+
cdouble = Double;
111+
{$EXTERNALSYM cfloat}
112+
113+
ppcint = ^pcint;
114+
pcint = ^cint;
115+
116+
ppcuint = ^pcuint;
117+
pcuint = ^cuint;
118+
119+
ppclong = ^pclong;
120+
pclong = ^clong;
121+
122+
ppculong = ^pculong;
123+
pculong = ^culong;
124+
{
125+
Integer type sizes based on:
126+
https://en.cppreference.com/w/c/language/arithmetic_types#Data_models
127+
}
128+
cint = cint32;
129+
cuint = cuint32;
130+
{$IF DEFINED(CPU32) OR DEFINED(CPU32BITS)}
131+
clong = cint32;
132+
culong = cuint32;
133+
{$ELSE} // 64-bit
134+
{$IFDEF MSWINDOWS}
135+
clong = cint32;
136+
culong = cuint32;
137+
{$ELSE}
138+
clong = cint64;
139+
culong = cuint64;
140+
{$ENDIF}
141+
{$ENDIF}
142+
{$EXTERNALSYM cint}
143+
{$EXTERNALSYM cuint}
144+
{$EXTERNALSYM clong}
145+
{$EXTERNALSYM culong}
146+
147+
{$ENDIF}
148+
149+
{ Data types for all compilers }
150+
type
151+
PPUInt8Array = ^PUInt8Array;
152+
PUInt8Array = ^TUInt8Array;
153+
TUInt8Array = array [0..MAXINT shr 1] of cuint8;
154+
155+
ppcuint8 = ^pcuint8;
156+
157+
{ "The following type designates an unsigned integer type [or signed respectivly]
158+
with the property that any valid pointer to void can be
159+
converted to this type, then converted back to a pointer
160+
to void, and the result will compare equal to the original
161+
pointer: uintptr_t"
162+
Source: https://pubs.opengroup.org/onlinepubs/000095399/basedefs/stdint.h.html
163+
}
164+
cuintptr_t = PtrUInt;
165+
{$EXTERNALSYM cuintptr_t}
166+
cintptr_t = PtrInt;
167+
{$EXTERNALSYM cintptr_t}
168+
169+
{$IFDEF WANT_CWCHAR_T}
170+
(* wchar_t is the "wide character" type of the C language.
171+
* The size of this type is platform- and compiler-dependent.
172+
*
173+
* While FPC does have it's own "wide character" type, System.WideChar,
174+
* that one is defined as always being 16-bits, so we can't re-use it here.
175+
*
176+
* When using FPC on Unices, the UnixType unit provides a wchar_t definition.
177+
*
178+
* On other systems/compiler combos, let's just go
179+
* by what the CPP reference wiki claims, i.e:
180+
* - wchar_t is 16-bits on Windows
181+
* - wchar_t is 32-bits on Linux "and many other non-Windows systems"
182+
*
183+
* See: https://en.cppreference.com/w/cpp/language/types#Character_types
184+
*)
185+
{$IF DEFINED(FPC) AND DEFINED(UNIX)}
186+
cwchar_t = UnixType.wchar_t;
187+
{$ELSE}
188+
{$IF DEFINED(WIN32) OR DEFINED(WIN64)}
189+
cwchar_t = cuint16;
190+
{$ELSE}
191+
cwchar_t = cuint32;
192+
{$ENDIF}
193+
{$ENDIF}
194+
{$EXTERNALSYM cwchar_t}
195+
pcwchar_t = ^cwchar_t;
196+
{$ENDIF}

0 commit comments

Comments
 (0)