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 PAA23774; Wed, 21 Jan 2004 15:37:42 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA23561 for ; Wed, 21 Jan 2004 15:37:41 +0100 (MET) Received: from mail4.tpgi.com.au (mail.tpgi.com.au [203.12.160.61]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i0LEbcv10313 for ; Wed, 21 Jan 2004 15:37:39 +0100 (MET) Received: from 203-219-235-5-syd-ts26-2600.tpgi.com.au (203-219-235-5-syd-ts26-2600.tpgi.com.au [203.219.235.5]) by mail4.tpgi.com.au (8.12.10/8.12.10) with ESMTP id i0LEbYle008904; Thu, 22 Jan 2004 01:37:35 +1100 Subject: Re: [Caml-list] Collateral effect with pointers From: skaller Reply-To: skaller@tpg.com.au To: =?ISO-8859-1?Q?ANDR=FFffffc9?= MOURA Cc: caml-list In-Reply-To: <20040121130704.38016.qmail@web60606.mail.yahoo.com> References: <20040121130704.38016.qmail@web60606.mail.yahoo.com> Content-Type: text/plain; charset=UTF-8 Message-Id: <1074695888.11497.42.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 22 Jan 2004 01:38:10 +1100 Content-Transfer-Encoding: 8bit X-TPG-Antivirus: Passed X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 collateral:99 pointers:01 tpg:99 2004:99 pointers:01 caveat:01 struct:01 struct:01 immutable:01 orient:99 0.0:01 immutable:01 tpg:99 glebe:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 2004-01-22 at 00:07, ANDRÿffffc9 MOURA wrote: > After exhausting tests, I believe that the problem is related to the > structure of pointers. In C, an assignment: *p = *q copies the value q points at to the location p points at. In Ocaml, with your construction, the same thing happens BUT there is a caveat. In Ocaml most values are boxed, which means the value is presented by a pointer. So suppose in the C assignment above the value being copied was a struct, then the whole struct would be copied .. but not in Ocaml. This is irrelevant for immutable data types.. > let dummytri = new_pointer ({tr_adjtri=(Array.init 3 (fun x -> > {te_ptri=Null; ta_orient=0})); tr_no=(Array.init 3 (fun x -> > dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); > tr_area=0.0});; .. but Ocaml arrays are not immutable. To copy an array, you will have to call Array.copy Note that of course if the elements IN the array are also not immutable .. that still won't work (since the array is just an array of pointers, Array.copy just copies the pointers). Perhaps this may be the source of your problem? -- John Max Skaller, mailto:skaller@tpg.com.au snail:25/85c Wigram Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850. Checkout Felix: http://felix.sf.net ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners