From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 10511BBAF for ; Sun, 14 Feb 2010 23:59:33 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAAMPeEtQRFuw/2dsb2JhbACbHXS6WYRbBIMu X-IronPort-AV: E=Sophos;i="4.49,472,1262559600"; d="scan'208";a="52735831" Received: from furbychan.cocan.org ([80.68.91.176]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/AES256-SHA; 14 Feb 2010 23:59:32 +0100 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1NgnR5-0008IG-DG; Sun, 14 Feb 2010 22:59:31 +0000 Date: Sun, 14 Feb 2010 22:59:31 +0000 To: Guillaume Yziquel Cc: OCaml List Subject: Re: [Caml-list] Wrapping var_args, or C ... in ocaml? Message-ID: <20100214225931.GC24949@annexia.org> References: <4B781ACC.4040603@citycable.ch> <20100214180650.GA22433@annexia.org> <4B787D32.10505@citycable.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <4B787D32.10505@citycable.ch> User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Spam: no; 0.00; ocaml:01 0100,:01 guillaume:01 varargs:01 unspecified:01 encodes:01 ocaml:01 well-typed:01 wrote:01 stack:01 caml-list:01 argument:02 theoretical:03 seems:03 scope:04 On Sun, Feb 14, 2010 at 11:46:10PM +0100, Guillaume Yziquel wrote: > Not the case. [etc] 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=20 > trickery in the concept. It looks that it is C that is not mapping the=20 > concept to its fullest potential. >=20 > I mean, it seems that varargs means on the receiving end "the number of= =20 > arguments you'r giving me, as a function, is not limited", whereas on=20 > 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 documentation. 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? Rich. --=20 Richard Jones Red Hat