Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Wrapping var_args, or C ... in ocaml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-02-14 (18:06)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Wrapping var_args, or C ... in ocaml?
On Sun, Feb 14, 2010 at 04:46:20PM +0100, Guillaume Yziquel wrote:
> Hello.
> I'm currently looking at:
> and I would like to know how to wrap up C functions with va_list of with 
> an ellipsis. Is this documented somewhere, or has someone already done 
> something like this?

It really depends on the function and how it will be used.  It
might translate to any of:

(1) A collection of functions implementing different aspects of the C
function.  eg. The open(2) function in Unix is really a varargs
function, and depending on whether you want to open a file for input,
output, create, etc. you'd probably be better off with different
functions in OCaml.  (Unix.openfile does _not_ do this ...)

(2) A simple list, eg. for a C function that takes a NULL-terminated
list of strings.

(3) A variant list of variants, or option labels, eg. for a C function
that takes 'type, value'(s), such TIFFSetField in
libtiff. (

(4) Something very specialized, eg. the 'printw' function in ncurses
is like printf and so would need quite a tricky implementation in
OCaml.  (Probably best to use ksprintf to convert to a string in OCaml
and then pass printw ("%s", str) in C).

In libguestfs where we autogenerate bindings we avoided varargs
altogether, because it's hard to map such a concept to all the
different languages we support.


Richard Jones
Red Hat