Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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,
snail:25/85c Wigram Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850. Checkout Felix:

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: