From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA29206; Thu, 31 Jan 2002 16:23:26 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 QAA27906 for ; Thu, 31 Jan 2002 16:23:24 +0100 (MET) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g0VFNND10962 for ; Thu, 31 Jan 2002 16:23:23 +0100 (MET) Received: from chopin.ai.univie.ac.at (root@chopin.ai.univie.ac.at [131.130.174.170]) by fichte.ai.univie.ac.at (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id QAA29922; Thu, 31 Jan 2002 16:23:22 +0100 Received: (from markus@localhost) by chopin.ai.univie.ac.at (8.9.3/8.9.3/Debian 8.9.3-21) id QAA29838; Thu, 31 Jan 2002 16:23:22 +0100 Date: Thu, 31 Jan 2002 16:23:22 +0100 From: Markus Mottl To: Tomasz Zielonka Cc: CAML list Subject: Re: [Caml-list] Using C values in ocaml code Message-ID: <20020131152322.GC27804@chopin.ai.univie.ac.at> Mail-Followup-To: Tomasz Zielonka , CAML list References: <20020131101112.GA30020@cs.net.pl> <20020131111251.GA27804@chopin.ai.univie.ac.at> <20020131150529.GA15230@cs.net.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020131150529.GA15230@cs.net.pl> User-Agent: Mutt/1.3.26i Organization: Austrian Research Institute for Artificial Intelligence Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 31 Jan 2002, Tomasz Zielonka wrote: > On Thu, Jan 31, 2002 at 12:12:51PM +0100, Markus Mottl wrote: > > You can't just cast 'x' to an OCaml-value: if it is an integer, you'll > > have to use the "Val_int"-macro. Otherwise the integer might exceed the > > range allowed by OCaml and could be interpreted as a pointer by the GC, > > possibly resulting in a crash (integers need to be tagged). > > It's even more fun. Odd ints would be interpreted as ints with halved > value, even ints as pointers. Yes, but since you were using an abstract type in the "external" declaration, you wouldn't have been able to add things within OCaml anyway. As long as the GC hadn't gone mad and killed the process, you'd have had to do computations within C-functions. > Both - an integer or a pointer. It is not always possible to check > whether it is a pointer or an integer not knowing the context. > > I will use abstract block then. This would be the best choice if you can't know the type of the C-value, if finalization is not needed and if handling of integers and pointers should be generic. Usually, you'll want to specialize the handling of integers and also unboxed floats whenever possible to improve performance (no indirection to access values). Regards, Markus Mottl -- Markus Mottl markus@oefai.at Austrian Research Institute for Artificial Intelligence http://www.oefai.at/~markus ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr