From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA06454 for caml-redistribution; Tue, 29 Apr 1997 19:44:23 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA03594 for ; Tue, 29 Apr 1997 17:42:19 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.5/8.7.3) with ESMTP id RAA25299; Tue, 29 Apr 1997 17:42:17 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA03587; Tue, 29 Apr 1997 17:42:16 +0200 (MET DST) From: Xavier Leroy Message-Id: <199704291542.RAA03587@pauillac.inria.fr> Subject: Re: Interfacing C procedure using an array as parameter ? In-Reply-To: <3364B837.4925@parc.anglia.ac.uk> from "Vincent B.G. Leleu" at "Apr 28, 97 03:46:15 pm" To: vincent@parc.anglia.ac.uk (Vincent B.G. Leleu) Date: Tue, 29 Apr 1997 17:42:16 +0200 (MET DST) Cc: caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis > This is the first time I interface C/OCaml and also I have > a problem : How do I use a parameter which is a pointer > on the beginning of an integer array ? To get you started, here are functions to convert between a C integer array and a Caml integer array. (Warning: untested code ahead.) value c_intarray_to_caml_intarray(int * carray, unsigned int nelts) { value mlarray; int i; mlarray = nelts < Max_young_wosize ? alloc(nelts, 0) : alloc_shr(nelts, 0); for (i = 0; i < nelts; i++) Field(mlarray, i) = Val_int(carray[i]); return mlarray; } int caml_intarray_to_c_intarray(value mlarray, int ** carray /*out parameter*/, unsigned int * nelts /*out parameter*/) { unsigned int len; int * p; int i; len = Wosize_val(mlarray); p = malloc(len * sizeof(int)); if (p == NULL) return -1; for (i = 0; i < len; i++) p[i] = Int_val(Field(mlarray, i)); *carray = p; *nelts = len; return 0; } Hope this helps, - Xavier Leroy