ctypes.inc 4.0 KB

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