[fpc-pascal] array of const with cdecl procedure

Bernd prof7bit at gmail.com
Mon Nov 12 12:46:39 CET 2012


2012/11/11 Jonas Maebe <jonas.maebe at elis.ugent.be>:

> No, it is not possible. There are no Pascal (or C, for that matter) expressions that map to particular registers on entry into the function.

ok, my wording was wrong. What I really meant to say was that if I am
absolutely determined to find a solution because I have no influence
on the calling side then it would still be possible to implement such
a function using only the means that are available in fpc. When I said
"is possible in Pascal" I really wanted to say "is possible with fpc
alone without having to make a separate C wrapper, even if it becomes
ridiculously complicated". Because "impossible" is such an absolute
word and used much too often I usually tend to not accept it without
proof.

I could for example make it an asm procedure (with separate
implementation for each architecture) that first takes the fixed
arguments and then pushes all remaining argument registers (if any) to
the stack and then calls a pascal procedure (the same for all
architectures) with the fixed arguments and a pointer to the register
save area and the number of saved registers and another pointer to the
stack area where to continue looking for more arguments should the
registers be exhausted. And the next step (if needed more than once)
would be to try to factor out most (or all?) of this into some easily
callable/includable code that resembles the functionality of the
va_start, va_arg and va_end macros and hides all the ifdef ugliness.



More information about the fpc-pascal mailing list