[fpc-pascal] Free Pascal bindings for EyeLink C code (with a god-cast)
Marco van de Voort
fpc at pascalprogramming.org
Tue Jun 13 11:25:13 CEST 2023
On 13-6-2023 05:19, Rafael Picanço via fpc-pascal wrote:
> (1) I have no idea on how to translate these god-casts, eg.,
> ((getExButtonStates)0), to free pascal. Right now, I think that even
> if I don't really need them, I just want to understand and learn
> in the process.
The problem is that the logical solution, making it a macro, doesn't
work, as macro definitions don't export through USES clauses.
Defining it a proper constant would be the best solution, but FPC
doesn't like it :
EXTERNAL_DEV_NONE = TGetExButtonStatesFunction(pointer(0));
so the next best is turning it into a type constant at the expense of
sizeof(pointer) bytes in the binary:
EXTERNAL_DEV_NONE : TGetExButtonStatesFunction= pointer(0);
> (2) So, the whole point here is binding the
> "enable_external_calibration_device" function. It expects a
> "getExButtonStates buttonStatesfcn". Can you check if my current
> binding is right?
A purist would say it needs to be "ansichar" rather than char (because
in future unicode modes char could be 2-byte, for the rest it seems ok.
> (3) I am using the ELCALLTYPE macro just because they were using them
> too, I am assuming backward compatibility. But I am not sure if I
> really need them. EyeLink code depends on custom SDL2 headers and I
> am running SDL2 Free Pascal related stuff just fine (and it has cdecl
> in everything). What do you think about that? For reference, this is
> the macro:
You must match the calling convention of the implementation. Some
functions have target dependent calling conventions, some non native
libraries force cdecl even on Windows. (where stdcall or fastcall is
Note that an alternative for this macro exists since FPC 3.2.0:
Even though the naming is not "elegant" for crossplatform usage.
More information about the fpc-pascal