[fpc-pascal] callback from c with varargs

Jonas Maebe jonas at freepascal.org
Sun Dec 20 14:48:31 CET 2020


On 20/12/2020 14:43, Tomas Hajny via fpc-pascal wrote:
> On 2020-12-20 14:00, Jonas Maebe via fpc-pascal wrote:
>> On 20/12/2020 13:01, Luca Olivetti via fpc-pascal wrote:
>>> El 19/12/20 a les 23:15, Jonas Maebe via fpc-pascal ha escrit:
>>>> It is indeed not possible to implement a function with C varargs in
>>>> FPC.
>>>
>>> I was afraid that's the answer :-(
>>>
>>> as an ugly workaround, I wrote a c library that vsnprintf msg and args
>>> to a buffer and then calls a pascal function with no varargs.
>>>
>>> It works but, as I said, it's ugly and I'd need to provide a .a for
>>> every platform I plan to use.
>>>
>>> Is there a better/simpler way (apart from asking the library developers
>>> to use a callback with no varargs)?
>>
>> No.
> 
> Not necessarily better than platform specific .a files mentioned by
> Luca, but the required playing with stack and registers should be still
> doable with a function written in assembler (inside the Pascal sources),
> shouldn't it?

Yes, but you'd have to write it separately for each ABI.


Jonas


More information about the fpc-pascal mailing list