From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,9506bdc34331969a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news1.google.com!news.glorb.com!news-in-01.newsfeed.easynews.com!easynews!core-easynews-01!easynews.com!en-nntp-03.dc1.easynews.com.POSTED!not-for-mail From: Rob Solomon Newsgroups: comp.lang.ada Subject: Re: put of access type Message-ID: <5rbp85p6q6lpcqm7sdouvc5qtgn5v0ts67@4ax.com> References: <8sho8596j3qnja38id9ipejk0opkcn5b5m@4ax.com> <68e68a01-eca6-4f17-9496-cc5d2eee7113@k26g2000vbp.googlegroups.com> <0gap85troslh5llfuiou61m67piv187fdr@4ax.com> X-Newsreader: Forte Agent 4.2/32.1118 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@easynews.com Organization: Forte Inc. http://www.forteinc.com/apn/ X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. Date: Wed, 19 Aug 2009 22:06:23 -0400 Xref: g2news2.google.com comp.lang.ada:7892 Date: 2009-08-19T22:06:23-04:00 List-Id: On Wed, 19 Aug 2009 21:54:05 -0400, Rob Solomon wrote: >>> >You probably meant the address of the pointed object. Here you go. Let Ptr >>> >be a pointer to some object >>> >>> >(with System.Storage_Elements; �use System.Storage_Elements;) >>> >>> > � Integer_Address'Image (To_Integer (Ptr.all'Address))); >>> >>> >Ptr.all'Address is the address of the object. To_Integer converts the >>> >address to a plain integer type (Integer_Address defined in >>> >System.Storage_Elements). This type can be output as any other. >>> >>> I am trying to understand this. � >>> >>> Back when I learned Modula-2, I learned that pointer types are >>> assignment compatible with System.Address and I understand them as >>> being the same thing. �They �differ in context, not value. >>> >>> I see that access types are being used the same as pointer types, but >>> if I understand correctly, are actually quite different. �But I don't >>> understand how. �ie, how are access types and pointers different? >> >>For simple types (integer; simple records) there's probably no >>difference. For types with constraints/discriminants, bets are off: >>consider >> >> S : access String := "foo"; >> >>S will most likely (this is compiler-dependent) *not* point to the 'f' >>in "foo"; it might point to a structure containing >> >> 4-byte integer, lower bound of string (= 1) >> 4-byte integer, upper bound of string (= 3) >> 1-byte character = f >> 1-byte character = o >> 1-byte character = o >> >>> What is the difference between integer_address and address? >> >>integer_address is some sort of integer, with 'image, "=", "-" etc; >>address is private, with no such operations (it does have comparators; >>see package System). >> >>integer_address'image is going to be up to about 10 (32-bit addresses) >>or 20 (64-bit addresses) characters long, and you are assigning it to >>a string of length 255; that won't work. > >This is what I came up with, that works. But I have another question, >to follow the code: > >procedure adr is > > type card32 is mod 4_294_967_296; > package card32_IO is new Ada.Text_IO.Modular_IO(card32); > > > X : aliased Integer := 1; > c,k : card32 := 0; > > P1,P2,P3 : Access Integer; > Str,S : String(1..255); > begin > P1 := X'Access; > P2 := P1; > P3 := new integer; > >Ada.Strings.Fixed.Move(Integer_Address'Image(To_Integer(P1.all'Address)),Str); > Move(System.Address_Image(P1.all'address),s); > C := >card32'value(Integer_Address'Image(To_Integer(P2.all'Address))); > K := >card32'value(Integer_Address'Image(To_Integer(P3.all'Address))); > put("Str = "); > put(Str); > new_line; > put("s = "); > put(s); > put("C = "); > Card32_io.put(c); > new_line; > put("K = "); > Card32_io.put(k); > new_line; > end adr; > >My question is that the value of Str and S should be equal, after >converting hex <-> decimal. They are not. I am getting this as the >relevent output >Str = 3215841220 >S = BFADD7C4 > >These numbers are not equal, according to my conversion. > >What am I missing? NEVERMIND I figured it out. The output is not putting all digits on the same line. When I corrected for this, the actual output does match when converting from hex <-> dec