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 SAA25632; Fri, 20 Feb 2004 18:29:10 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA26318 for ; Fri, 20 Feb 2004 18:29:08 +0100 (MET) Received: from web60603.mail.yahoo.com (web60603.mail.yahoo.com [216.109.118.223]) by concorde.inria.fr (8.12.10/8.12.10) with SMTP id i1KHT7ae012421 for ; Fri, 20 Feb 2004 18:29:07 +0100 Message-ID: <20040220172906.7855.qmail@web60603.mail.yahoo.com> Received: from [200.137.225.200] by web60603.mail.yahoo.com via HTTP; Fri, 20 Feb 2004 14:29:06 ART Date: Fri, 20 Feb 2004 14:29:06 -0300 (ART) From: =?iso-8859-1?q?Andr=E9=20Luiz=20Moura?= Subject: [Caml-list] Value of the address of a pointer To: caml-list@inria.fr MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-2099931439-1077298146=:7788" Content-Transfer-Encoding: 8bit X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; printf:01 printf:01 W8:99 ocaml:01 ocaml:01 int:01 int:01 config:02 W5:97 W5:97 address:96 address:96 pointer:03 pointer:03 array:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --0-2099931439-1077298146=:7788 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit 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! --0-2099931439-1077298146=:7788 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit
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! --0-2099931439-1077298146=:7788-- ------------------- 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 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 QAA14238; Tue, 24 Feb 2004 16:19:27 +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 QAA11960 for ; Tue, 24 Feb 2004 16:19:26 +0100 (MET) Received: from gw02.mail.saunalahti.fi (gw02.mail.saunalahti.fi [195.197.172.116]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i1OFJQIq012719 for ; Tue, 24 Feb 2004 16:19:26 +0100 Received: from oro (naked.iki.fi [62.142.249.112]) by gw02.mail.saunalahti.fi (Postfix) with ESMTP id 14CC7F1784F; Tue, 24 Feb 2004 17:19:25 +0200 (EET) Received: from naked by oro with local (Exim 3.36 #1 (Debian)) id 1AveLE-000457-00; Tue, 24 Feb 2004 17:19:24 +0200 To: =?iso-8859-1?q?Andr=E9_Luiz_Moura?= Cc: caml-list@inria.fr Subject: Re: [Caml-list] Value of the address of a pointer References: <20040220172906.7855.qmail@web60603.mail.yahoo.com> From: Nuutti Kotivuori Date: Tue, 24 Feb 2004 17:19:23 +0200 In-Reply-To: <20040220172906.7855.qmail@web60603.mail.yahoo.com> (Andr's message of "Fri, 20 Feb 2004 14:29:06 -0300 (ART)") Message-ID: <87ishw7bes.fsf@naked.iki.fi> User-Agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Portable Code, linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 newbie:01 ocaml:01 ocaml:01 caml:01 address:96 address:96 pointer:03 pointer:03 wrote:03 array:04 array:04 separately:05 iki:07 i'm:07 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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