caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Value of the address of a pointer
@ 2004-02-20 17:29 André Luiz Moura
  2004-02-24 15:19 ` Nuutti Kotivuori
  0 siblings, 1 reply; 2+ messages in thread
From: André Luiz Moura @ 2004-02-20 17:29 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]

Hello,
 
Please, it would like to know as to get in OCaml the value of the address of memory of a pointer, as it occurs in the example in C that follows:

Code:
void main()
{
   int my_array[] = {1, 23, 17};
   int *ptr;
   int i;
 
   ptr = &my_array[0];         /* point  to the first element of the array */
   for (i = 0; i < 3; i++) {
      printf("\nvalue of my_array[%d] = %d; ", i, my_array[i]);
      printf("value of ptr + %d = %d\n",i, *(ptr + i)); 
      printf("address of my_array[%d] = %x; ", i, &my_array[i]);
      printf("address of ptr = %x\n", (ptr + i)); 
}
 
Result:
value of my_array[0] = 1; value of ptr + 0 = 1
address of my_array[0] = 12ff80; address of ptr = 12ff80
 
value of my_array[1] = 23; value of ptr + 1 = 23
address of my_array[1] = 12ff84; address of ptr = 12ff84
 
value of my_array[2] = 17; value of ptr + 2 = 17
address of my_array[2] = 12ff88; address of ptr = 12ff88
 
Thanks,
 
André
 





---------------------------------
Yahoo! Mail - O melhor e-mail do Brasil. Abra sua conta agora!

[-- Attachment #2: Type: text/html, Size: 1587 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Value of the address of a pointer
  2004-02-20 17:29 [Caml-list] Value of the address of a pointer André Luiz Moura
@ 2004-02-24 15:19 ` Nuutti Kotivuori
  0 siblings, 0 replies; 2+ messages in thread
From: Nuutti Kotivuori @ 2004-02-24 15:19 UTC (permalink / raw)
  To: André Luiz Moura; +Cc: caml-list

Andr wrote:
> Please, it would like to know as to get in OCaml the value of the
> address of memory of a pointer, as it occurs in the example in C
> that follows:

You cannot obtain a pointer to a certain element in an array in
OCaml. And in any case it does not make sense unless you plan on
modifying the element.

If you do plan on modifying it, you will either have to carry both the
array itself and an index to the element inside it separately - or you
will have to have an array of references to values and use it
accordingly then.

I'm a relative OCaml newbie though, so hopefully someone will correct
me if I am wrong.

-- Naked

-------------------
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-02-24 15:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-20 17:29 [Caml-list] Value of the address of a pointer André Luiz Moura
2004-02-24 15:19 ` Nuutti Kotivuori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).