I think that what I should be doing is defining the interface to the external library as cdecl but the internal shim function as using the Pascal calling convention, or (better) the external one as array-of-const+cdecl and the shim as array-of-const which would allow the caller to use the Object Pascal [] parameter list.
It's obviously a bit of extra work in the program that generates the interface units, but nothing insuperable since it's reasonable to expect the writer of the input file to be fairly careful with his definitions.
That is the most useful solution. FPC does not support this, because every C compiler handles the implementation side differently, so we didn't want to bother with this. (And you can be sure if we'd provide support for implementing varargs routines that users would want their code to be useable from C and in Pascal we have array of const already anyway)
Thanks for that. So if you could double-check my philosophy:
* Leave the static interface unchanged, i.e. the declarations have cdecl and possibly varargs.
* The field (entry point pointer) in the dynamic interface keep cdecl/varargs.
* The class declaration and implementation in the dynamic interface lose cdecl/varargs.
* Where necessary, the class declaration and implementation have varargs rewritten as array of const.
The simplest way of doing that would be to declare new macros CDECL__ and CDECL_VARARGS___ or similar.
Can you confirm that these examples from the Reference really are equivalent in all situations:
Function PrintF1(fmt : pchar ); cdecl; varargs; external ’c’ name ’printf’;
Function PrintF2(fmt : pchar; Args : Array of const); cdecl; external ’c’ name ’printf’;
In MacPas mode, is "..." a precise equivalent of "array of const"?
The preprocessor is handling stuff fairly naively, but it works and saves a vast amount of manual editing. In the past I've used pretty much the same approach to also define the exports from a dynamically-linkable unit.
MarkMLl