From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id SAA01918 for caml-redistribution; Tue, 24 Sep 1996 18:41:50 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id PAA26812 for ; Tue, 24 Sep 1996 15:36:41 +0200 Received: from nef.ens.fr (nef.ens.fr [129.199.96.12]) by concorde.inria.fr (8.7.6/8.7.1) with SMTP id PAA12283 for ; Tue, 24 Sep 1996 15:36:40 +0200 (MET DST) Received: from vedette.ens.fr by nef.ens.fr (5.65c8/ULM-1.0) Id AA24876 ; Tue, 24 Sep 1996 15:36:39 +0200 Received: from nave.ens.fr by vedette.ens.fr (4.1/version 1.10 of 88/05/05) id AA27204; Tue, 24 Sep 96 15:36:38 +0200 Date: Tue, 24 Sep 1996 15:36:36 +0200 (MET DST) From: Jerome Vouillon Sender: weis Reply-To: Jerome Vouillon Subject: Re: Need help: O'Caml C Interface To: Frank Christoph Cc: caml-list@pauillac.inria.fr In-Reply-To: <9609231509.AA03139@sparc3.nextsolution.co.jp> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII > value ocaml_getCharWidth(value code) > { > double x, y; > Push_roots(r,1); > > r[0] = alloc_tuple(2); > getCharWidth(Int_val(code),&x,&y); > Store_double_val(Field(r[0],0),x); > Store_double_val(Field(r[0],1),y); > Pop_roots(); > return r[0]; > } I would write it this way: value ocaml_getCharWidth(value code) { double x, y; value res; Push_roots(r,2); getCharWidth(Int_val(code),&x,&y); r[0] = copy_double(x); r[1] = copy_double(y); res = alloc_tuple(2); Field(res, 0) = r[0]; Field(res, 1) = r[1]; Pop_roots(); return res; } Store_double_val is used to store a double in an array of double values (which is a special kind of array). In other cases, you have to use copy_double to allocate a block containing the double. So, your code failed because Field(r[0],0) was not a pointer to an array, but an uninitialized pointer. *_roots are used to keep a pointer to both double values. Indeed, these values can be moved by copy_double or alloc_tuple. The tuple is allocated last, so that it can be directly filled (without having to use function modify). Jerome