[Prev][Next][Index][Thread]

Re: C functions with variable parm lists



On Fri, 12 May 2000 johncwhi@my-deja.com wrote:
> How would you declare a Dylan C-ffi function to call, for example,
> sprintf in FD 2.0?
> Since sprintf has the signature
> int sprintf( char *buffer, const char *format [, argument] ... ) in
> which "argument"
> has no type and can be variable in number, the C-ffi doesn't appear to
> handle this case.
> Is it possible?

AFAIK there's no way to call a varargs function directly through the
C-FFI.  I looked up the comp.lang.c FAQ and the section (15) on
variable-length argument lists seems to suggest that, unless you have a
version of your function written specially to work with <stdarg.h> (e.g.,
vprintf) you're stuck.  There isn't any C version of Dylan's "apply"
apart from this.  See <http://www.faqs.org/faqs/C-faq/faq/>.

So maybe for printf (and scanf under "C9X", whatever that is) you can do
it -- otherwise, find a function which doesn't use varargs ;-)

Presenting a Dylan function to C as if it were a varargs function should
be easier, by writing a wrapper in the other direction, using the
<stdarg.h> stuff as one usually does.

HTH,
Hugh




References: