Hello,
Some days ago, I did a conversion from a C header to Pascal, and I noticed that H2Pas tool could implement a little bit improvement for Variadic[1] (or varargs) functions conversion.
Consider the following C function with `varargs`:
int function foo(int bar, ...) {};I can call this function in two ways:
1. foo("Bar");
2. foo("Bar", "some", "separed", "arguments", "without", "squared", "braces").
Usually, H2Pas convert it overloaded:
function foo(bar: cint): cint; cdecl ...
function foo(bar: cint; args: array of const): cint; cdecl ...And it doesn't work when a code needs to work both in FPC and Delphi. For Delphi compiler, to compile the converted header, you needs to specify the overload directive:
function foo(bar: cint): cint; cdecl; overload ...
function foo(bar: cint; args: array of const): cint; cdecl; overload ...But, even specifying the overload, the converted function doesn't works in Delphi. But someone can say: why Delphi, Mr? No special reason, currently I just write code that needs to compile both in FPC and Delphi.
OK, but, how to declare a variadic function in FPC/Delphi? It is very easy:
function foo(bar: cint): cint; verargs; cdecl; ...Let's go to read its documentation:
This modifier can only be used together with the cdecl modifier, for
Show quoted text 6 lines
Great! So, using the varargs directive, I can declare and use my function more C-like. =)
We already use something like this in WriteLn/ReadLn, eg:
WriteLn('some', 'separed', 'arguments', 'without', 'squared', 'braces').
So, after this little explanation, what do you think about add a new param in H2Pas tool? Something like:
-V Declare C variadic functions with varargs directive.
Thank you!
[1] https://en.wikipedia.org/wiki/Variadic_function [2] http://www.freepascal.org/docs-html/ref/refsu83.html
