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 (22:59)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Wrapping var_args, or C ... in ocaml?
On Sun, Feb 14, 2010 at 11:46:10PM +0100, Guillaume Yziquel wrote:
> Not the case.

It would help if you were to be more specific about the function that
you're trying to bind.

> But, I mean, from the point of view of the ABI, there's not much 
> trickery in the concept. It looks that it is C that is not mapping the 
> concept to its fullest potential.
> I mean, it seems that varargs means on the receiving end "the number of 
> arguments you'r giving me, as a function, is not limited", whereas on 
> the sending end, you hard-code the number of arguments in your C code.

In the C case the sender pushes arguments right to left on the stack,
and the receiver must deduce in an unspecified way how many arguments
were pushed.  This can be because the sender promises to
NULL-terminate the list, or encodes in an earlier argument some
indication of how many arguments follow, or they might even have given
it in a previous function call, or have just agreed it in the

If the receiver gets it wrong, there is plenty of scope for
catastrophic errors to occur -- and this is not merely a theoretical
problem, but a very real problem that many C programmers have
encountered.  So I'm quite happy that OCaml doesn't make this kind of
poorly-specified function easy to implement.

> Is there a way to map an OCaml list to an ellipsis? Or is it a C
> limitation?

I'm not sure exactly what this means.  An OCaml list is a
well-defined, well-typed version of the C ellipsis isn't it?


Richard Jones
Red Hat