That is not a simple thing to do.

If your function expects a variable length list of arguments of different types, the best approach would probably be to replace it by another function accepting a list of SVs, implemented using lower level functions.

Another option would be to implement the formating part in Perl, for instance:

sub FWriteF { my $file = shift; my $fmt = shift; my $text = sprintf($fmt, @_); _FRwriteF($file, $text); # calls C function as # FWriteF($file, "%s", $text); }

If your function expects a variable list of arguments of the same type, sometimes it is acceptable to set a limit on the number or arguments so you can use something like this:

int FWriteF(file, fmt, a0=0, a1=0, a2=0, a3=0,...., a10=0) FILE *file, const char *fmt int a0 int a1 ... int a10 CODE: switch (items - 2) { case 0: RETVAL = FWriteF(file, fmt); break; case 1: RETVAL = FWriteF(file, fmt, a1); break; case 0: RETVAL = FWriteF(file, fmt, a1, a2); break; ... case 10: RETVAL = FWriteF(file, fmt, a1, a2, a3, ..., a10); break; } OUTPUT: RETVAL
If I recall correctly, that's how SWIG does, for instance.

In reply to Re: C Functions with variable argument list in perlxs by salva
in thread C Functions with variable argument list in perlxs by Temeschwarrior

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.