English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Collateral effect with pointers
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-01-21 (14:37)
From: skaller <skaller@t...>
Subject: Re: [Caml-list] Collateral effect with pointers
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


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