Eric Wilhelm wrote:
> # The following was supposedly scribed by
> # Sisyphus
> # on Saturday 21 August 2004 12:53 am:
>
>
>>> void c_printf(char *format, AV * arguments) {
>>> ...
>>
>>
>> It's the code that goes in here that I'm struggling with. There's no
>> problem with passing the first argument to C's printf function, but how
>> does one pass the arguments contained in the array reference to C's
>> printf (or vprintf) function ? Is that also trivial ?
>
>
>
> Are you really trying to solve the printf(fmt, arg1 arg2 arg3) problem, or just the variable length arguments?
>
I'm fairly comfortable with passing variable length argument lists to Inline C functions but I seem to be stuck when it comes to passing the arguments contained in that (variable length) list to a C function that itself takes a variable length list.
I'm using the C 'printf' function in my example code simply because it's a familiar case of a C function that takes a variable length list of args.
In reality, I would like to wrap the GMP library's gmp_printf function. That function is analogous to C's printf function - it takes a 'char * format' as its first argument, followed by however many GMP objects as subsequent arguments. If I can work out how to wrap printf/vprintf, then (I hope) it will not be difficult to adapt that process to wrapping gmp_printf/gmp_vprintf.
> Do you want to pass an array reference or an array?
Preferably an array - but if passing an array reference makes it easier to pass the arguments on to 'printf' (or 'vprintf') then I'll do it that way.
>
> The Inline::C-Cookbook has a good example for using Inline_Stack_Vars and such to deal with arrays, but the generic printf emulation implies a lot more about typemaps and unpacking each element of the list.
>
Hmmm .... I've been starting to fear that there's going to be much more to this than I originally thought. The last part of that sentence does little to allay that fear :-)
Thanks Eric.
Cheers, Rob