<div dir="ltr"><div dir="ltr">Hi Marco,<div><br></div><div>I am trying to follow your advice and use units instead:</div><div><br></div><div>const<br>  EXTERNAL_DEV_NONE : TGetExButtonStatesFunction = Pointer(0);</div><div> <br></div><div>However I am receiving an error:</div><div><br></div><div>Error: Incompatible types: got "Pointer" expected "<procedure variable type of function(PCCDBS):LongInt;CDecl>"<br></div><div><br></div><div>Please, can you shed some light on this?</div><div><br></div><div>Best,</div><div>R</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 14, 2023 at 7:00 AM <<a href="mailto:fpc-pascal-request@lists.freepascal.org">fpc-pascal-request@lists.freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Send fpc-pascal mailing list submissions to<br>
        <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:fpc-pascal-request@lists.freepascal.org" target="_blank">fpc-pascal-request@lists.freepascal.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:fpc-pascal-owner@lists.freepascal.org" target="_blank">fpc-pascal-owner@lists.freepascal.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of fpc-pascal digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Re:  fpc isn't optimised for tail recursion, is it?<br>
      (Jean SUZINEAU)<br>
   2. Re:  Free Pascal bindings for EyeLink C code (with a<br>
      god-cast) (Rafael Pican?o)<br>
   3. Re:  Free Pascal bindings for EyeLink C code (with a<br>
      god-cast) (Marco van de Voort)<br>
   4. Re:  Non-initialized member access warning (Hairy Pixels)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Tue, 13 Jun 2023 15:25:59 +0200<br>
From: Jean SUZINEAU <<a href="mailto:jean.suzineau@wanadoo.fr" target="_blank">jean.suzineau@wanadoo.fr</a>><br>
To: <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
Subject: Re: [fpc-pascal] fpc isn't optimised for tail recursion, is<br>
        it?<br>
Message-ID: <<a href="mailto:310a7c2b-a874-b5d3-f80f-f492903580d7@wanadoo.fr" target="_blank">310a7c2b-a874-b5d3-f80f-f492903580d7@wanadoo.fr</a>><br>
Content-Type: text/plain; charset="utf-8"; Format="flowed"<br>
<br>
Le 12/06/2023 ? 19:05, Steve Litt via fpc-pascal a ?crit?:<br>
> Busted! I used Pascal 1984-1993<br>
So I guess you are not familiar too with the "Result" variable which <br>
appeared with Delphi 1 in 1995 if I remember correctly.<br>
<br>
nextt:= num;<br>
<br>
can be written to as :<br>
<br>
Result:= num;<br>
<br>
<a href="https://www.freepascal.org/docs-html/ref/refse94.html" rel="noreferrer" target="_blank">https://www.freepascal.org/docs-html/ref/refse94.html</a><br>
<br>
I prefer Result because it reduces risks of confusion with recursive call<br>
and you can eventually take the address of Result with @Result (where <br>
@nextt would take the address of the function nextt),<br>
pass it by reference to another function ( e.g. FillChar( Result, <br>
SizeOf(Result), 0); ) ,<br>
it behaves like a normal variable.<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230613/5a2bb3c5/attachment-0001.htm" rel="noreferrer" target="_blank">http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230613/5a2bb3c5/attachment-0001.htm</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Tue, 13 Jun 2023 10:38:22 -0300<br>
From: Rafael Pican?o <<a href="mailto:cpicanco42@gmail.com" target="_blank">cpicanco42@gmail.com</a>><br>
To: <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
Subject: Re: [fpc-pascal] Free Pascal bindings for EyeLink C code<br>
        (with a god-cast)<br>
Message-ID:<br>
        <CAGpuCi5mjRLeCnMY=<a href="mailto:mhrBM9kjf7r%2BBRv6yRr3YDXT8njuHT2Cw@mail.gmail.com" target="_blank">mhrBM9kjf7r+BRv6yRr3YDXT8njuHT2Cw@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Thank you Marco, I am elaborating on top of your suggestions.<br>
<br>
> The problem is that the logical solution, making it a macro, doesn't<br>
work, as macro definitions don't export through USES clauses.<br>
<br>
I think that pre-processor constants with $I would be a valid alternative<br>
for using the best solution. For example:<br>
<br>
// constants.pp<br>
____<br>
{$MACRO ON}<br>
{$ifndef EXTERNAL_DEV_NONE}<br>
  {$DEFINE EXTERNAL_DEV_NONE := TGetExButtonStatesFunction(Pointer(0))}<br>
{$endif}<br>
{$ifndef EXTERNAL_DEV_CEDRUS}<br>
  {$DEFINE EXTERNAL_DEV_CEDRUS := TGetExButtonStatesFunction(Pointer(1))}<br>
{$endif}<br>
{$ifndef EXTERNAL_DEV_SYS_KEYBOARD}<br>
  {$DEFINE EXTERNAL_DEV_SYS_KEYBOARD :=<br>
TGetExButtonStatesFunction(Pointer(2))}<br>
{$endif}<br>
____<br>
<br>
program godcastsucks;<br>
<br>
{$I constants}<br>
<br>
type<br>
<br>
  PCCDBS = ^TCCDBS;<br>
  TCCDBS = record<br>
    userdata: Pointer;<br>
    buttons: array[0..255] of AnsiChar;<br>
    internal: Pointer;<br>
  end;<br>
<br>
  TGetExButtonStatesFunction = function (accdbs: PCCDBS): Int32; cdecl;<br>
<br>
  function enable_external_calibration_device(<br>
    buttonStatesfcn: Pointer {other arguments removed for simplicity}):<br>
Int32; cdecl;<br>
  var<br>
    Statesfcn : TGetExButtonStatesFunction;<br>
  begin<br>
    Result := Int32(TGetExButtonStatesFunction(@buttonStatesfcn^));<br>
    case Result of<br>
      0 : { do nothing };<br>
    else<br>
      begin<br>
        Statesfcn := TGetExButtonStatesFunction(buttonStatesfcn);<br>
        Statesfcn(nil);<br>
        Result := -1;<br>
      end;<br>
    end;<br>
  end;<br>
<br>
function ExButtonStatesFunction(accdbs: PCCDBS): Int32; cdecl;<br>
begin<br>
  WriteLn('God casts sucks');<br>
end;<br>
<br>
begin<br>
  WriteLn(enable_external_calibration_device(EXTERNAL_DEV_NONE));<br>
  WriteLn(enable_external_calibration_device(@ExButtonStatesFunction));<br>
  ReadLn;<br>
end.<br>
____<br>
<br>
> Note that an alternative for this macro exists since FPC 3.2.0:<br>
<br>
Thank you for the reference!<br>
<br>
On Tue, Jun 13, 2023 at 7:00?AM <<a href="mailto:fpc-pascal-request@lists.freepascal.org" target="_blank">fpc-pascal-request@lists.freepascal.org</a>><br>
wrote:<br>
<br>
> Send fpc-pascal mailing list submissions to<br>
>         <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
><br>
> To subscribe or unsubscribe via the World Wide Web, visit<br>
>         <a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
> or, via email, send a message with subject or body 'help' to<br>
>         <a href="mailto:fpc-pascal-request@lists.freepascal.org" target="_blank">fpc-pascal-request@lists.freepascal.org</a><br>
><br>
> You can reach the person managing the list at<br>
>         <a href="mailto:fpc-pascal-owner@lists.freepascal.org" target="_blank">fpc-pascal-owner@lists.freepascal.org</a><br>
><br>
> When replying, please edit your Subject line so it is more specific<br>
> than "Re: Contents of fpc-pascal digest..."<br>
><br>
><br>
> Today's Topics:<br>
><br>
>    1. Re:  Free Pascal bindings for EyeLink C code (with a<br>
>       god-cast) (Marco van de Voort)<br>
><br>
><br>
> ----------------------------------------------------------------------<br>
><br>
> Message: 1<br>
> Date: Tue, 13 Jun 2023 11:25:13 +0200<br>
> From: Marco van de Voort <<a href="mailto:fpc@pascalprogramming.org" target="_blank">fpc@pascalprogramming.org</a>><br>
> To: <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
> Subject: Re: [fpc-pascal] Free Pascal bindings for EyeLink C code<br>
>         (with a god-cast)<br>
> Message-ID:<br>
>         <<a href="mailto:5a5a8eac-e91d-d9d7-4131-d7301ec3c4d3@pascalprogramming.org" target="_blank">5a5a8eac-e91d-d9d7-4131-d7301ec3c4d3@pascalprogramming.org</a>><br>
> Content-Type: text/plain; charset=UTF-8; format=flowed<br>
><br>
><br>
> On 13-6-2023 05:19, Rafael Pican?o via fpc-pascal wrote:<br>
> > (1) I have no idea on how to translate these god-casts, eg.,<br>
> > ((getExButtonStates)0), to free pascal. Right now, I think that even<br>
> > if I don't really need them, I just want?to understand and learn<br>
> > in?the?process.<br>
><br>
> The problem is that the logical solution, making it a macro, doesn't<br>
> work, as macro definitions don't export through USES clauses.<br>
><br>
> Defining it a proper constant would be the best solution, but FPC<br>
> doesn't like it :<br>
><br>
> const<br>
><br>
>  ?EXTERNAL_DEV_NONE = TGetExButtonStatesFunction(pointer(0));<br>
><br>
> so the next best is turning it into a type constant at the expense of<br>
> sizeof(pointer) bytes in the binary:<br>
><br>
> const<br>
><br>
>  ? EXTERNAL_DEV_NONE : TGetExButtonStatesFunction= pointer(0);<br>
><br>
> etc etc.<br>
><br>
> ><br>
> > (2) So, the whole point here is?binding the<br>
> > "enable_external_calibration_device" function. It expects a<br>
> > "getExButtonStates buttonStatesfcn". Can you check if my current<br>
> > binding is right?<br>
> ><br>
> A purist would say it needs to be "ansichar" rather than char (because<br>
> in future unicode modes char could be 2-byte, for the rest it seems ok.<br>
><br>
> > (3) I am using the?ELCALLTYPE?macro just because?they were?using them<br>
> > too,?I am assuming backward compatibility. But I am not sure if I<br>
> > really need them. EyeLink code depends on custom SDL2 headers and I<br>
> > am?running SDL2 Free Pascal related stuff just fine (and it has cdecl<br>
> > in everything). What do you think about that? For reference, this is<br>
> > the macro:<br>
> ><br>
> You must match the calling convention of the implementation. Some<br>
> functions have target dependent calling conventions, some non native<br>
> libraries force cdecl even on Windows. (where stdcall or fastcall is<br>
> more conventional)<br>
><br>
> Note that an alternative for this macro exists since FPC 3.2.0:<br>
><br>
><br>
> <a href="https://wiki.freepascal.org/FPC_New_Features_3.2.0#Support_for_WinAPI_directive" rel="noreferrer" target="_blank">https://wiki.freepascal.org/FPC_New_Features_3.2.0#Support_for_WinAPI_directive</a><br>
><br>
> Even though the naming is not "elegant" for crossplatform usage.<br>
><br>
><br>
> ------------------------------<br>
><br>
> Subject: Digest Footer<br>
><br>
> _______________________________________________<br>
> fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
> <a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
><br>
><br>
> ------------------------------<br>
><br>
> End of fpc-pascal Digest, Vol 228, Issue 14<br>
> *******************************************<br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230613/59aaf75a/attachment-0001.htm" rel="noreferrer" target="_blank">http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230613/59aaf75a/attachment-0001.htm</a>><br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Tue, 13 Jun 2023 15:48:36 +0200<br>
From: Marco van de Voort <<a href="mailto:fpc@pascalprogramming.org" target="_blank">fpc@pascalprogramming.org</a>><br>
To: <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
Subject: Re: [fpc-pascal] Free Pascal bindings for EyeLink C code<br>
        (with a god-cast)<br>
Message-ID:<br>
        <<a href="mailto:7e225875-c784-019a-1091-a89f612ef423@pascalprogramming.org" target="_blank">7e225875-c784-019a-1091-a89f612ef423@pascalprogramming.org</a>><br>
Content-Type: text/plain; charset=UTF-8; format=flowed<br>
<br>
<br>
On 13-6-2023 15:38, Rafael Pican?o via fpc-pascal wrote:<br>
> Thank you Marco, I am elaborating on top of your suggestions.<br>
><br>
> > The problem is that the logical solution, making it a macro, doesn't<br>
> work, as macro definitions don't export through USES clauses.<br>
><br>
> I think that pre-processor constants with $I would be a valid <br>
> alternative for using the best solution. For example:<br>
><br>
A matter of taste. I would have as less macros as possible. Moreover the <br>
typed const doesn't require including additional files at the usage <br>
site, so IMHO it is objectively a better solution<br>
<br>
<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Wed, 14 Jun 2023 13:50:34 +0700<br>
From: Hairy Pixels <<a href="mailto:genericptr@gmail.com" target="_blank">genericptr@gmail.com</a>><br>
To: Sven Barth <<a href="mailto:pascaldragon@googlemail.com" target="_blank">pascaldragon@googlemail.com</a>><br>
Cc: FPC-Pascal users discussions <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a>><br>
Subject: Re: [fpc-pascal] Non-initialized member access warning<br>
Message-ID: <<a href="mailto:86575BA9-8FE9-4216-BCA0-94991010FA71@gmail.com" target="_blank">86575BA9-8FE9-4216-BCA0-94991010FA71@gmail.com</a>><br>
Content-Type: text/plain;       charset=us-ascii<br>
<br>
<br>
<br>
> On Jun 8, 2023, at 6:01 PM, Sven Barth <<a href="mailto:pascaldragon@googlemail.com" target="_blank">pascaldragon@googlemail.com</a>> wrote:<br>
> <br>
> Please report a bug with a complete example.<br>
<br>
Better late than never :)<br>
<br>
<a href="https://gitlab.com/freepascal.org/fpc/source/-/issues/40321" rel="noreferrer" target="_blank">https://gitlab.com/freepascal.org/fpc/source/-/issues/40321</a><br>
<br>
Regards,<br>
Ryan Joseph<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
<br>
<br>
------------------------------<br>
<br>
End of fpc-pascal Digest, Vol 228, Issue 15<br>
*******************************************<br>
</blockquote></div></div>