Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@tpg.com.au>
To: "ANDRÿffffc9 MOURA" <aluizmoura@yahoo.com.br>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Collateral effect with pointers
Date: 22 Jan 2004 01:38:10 +1100	[thread overview]
Message-ID: <1074695888.11497.42.camel@localhost.localdomain> (raw)
In-Reply-To: <20040121130704.38016.qmail@web60606.mail.yahoo.com>

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


      reply	other threads:[~2004-01-21 14:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-21 13:07 ANDRÿffffc9 MOURA
2004-01-21 14:38 ` skaller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1074695888.11497.42.camel@localhost.localdomain \
    --to=skaller@tpg.com.au \
    --cc=aluizmoura@yahoo.com.br \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox