[fpc-pascal] array of const with cdecl procedure

Bernd prof7bit at gmail.com
Sun Nov 11 20:42:35 CET 2012

2012/11/11 Sven Barth <pascaldragon at googlemail.com>:

> Yes and this is exactly what the change states. You can not write "varargs"
> functions in Pascal that can be accessed from C.

Wouldn't it be possible to write a function in pascal that declares a
simple longint parameter instead of the varargs and then inside the
function use the stack pointer (the address of that argument) to read
the entire list from the stack directly? Since in cdecl the caller
will clean up the stack after the function call this should not cause
any problems?

something along these lines (for example if a list of longints should
be passed):

procedure FakeVararg(dummy: LongInt);
  Start: PLongInt;
  First, Second, Third: LongInt;

  Start := PLongInt(@dummy);

  First := Start[0];
  Second := Start[1];
  Third := Start[2];


(or something very similar to this, not sure if the above code works
already, not tested)

More information about the fpc-pascal mailing list