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,FREEMAIL_FROM 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: g2news1.google.com!postnews.google.com!k26g2000vbp.googlegroups.com!not-for-mail From: sjw Newsgroups: comp.lang.ada Subject: Re: put of access type Date: Wed, 19 Aug 2009 12:44:03 -0700 (PDT) Organization: http://groups.google.com Message-ID: <68e68a01-eca6-4f17-9496-cc5d2eee7113@k26g2000vbp.googlegroups.com> References: <8sho8596j3qnja38id9ipejk0opkcn5b5m@4ax.com> NNTP-Posting-Host: 82.30.110.254 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1250711043 21397 127.0.0.1 (19 Aug 2009 19:44:03 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 19 Aug 2009 19:44:03 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k26g2000vbp.googlegroups.com; posting-host=82.30.110.254; posting-account=_RXWmAoAAADQS3ojtLFDmTNJCT0N2R4U User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:6909 Date: 2009-08-19T12:44:03-07:00 List-Id: On Aug 19, 8:00=A0pm, Rob Solomon wrote: > >> I would like to output a pointer to the screen. =A0(I am just learning > >> Ada). =A0 > > >> How do I put(Any_Access_Type) > > >You probably meant the address of the pointed object. Here you go. Let P= tr > >be a pointer to some object > > >(with System.Storage_Elements; =A0use System.Storage_Elements;) > > > =A0 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. =A0 > > 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. =A0They =A0differ 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. =A0But I don't > understand how. =A0ie, 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 :=3D "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 (=3D 1) 4-byte integer, upper bound of string (=3D 3) 1-byte character =3D f 1-byte character =3D o 1-byte character =3D o > What is the difference between integer_address and address? integer_address is some sort of integer, with 'image, "=3D", "-" etc; address is private, with no such operations (it does have comparators; see package System). > I need help with this code: > > procedure adr is > > c: integer; > x: aliased integer; > p1, p2 : access integer; > str : string (1..255); > > Begin > =A0 p1 :=3D x'access; > =A0 p2 :=3D p1; > =A0 str :=3D integer_address'image(to_integer(p1.all'address)); > =A0 c :=3D integer(to_integer(p2.all'address)); > > some put statements > end adr; > > This compiles w/ GNAT under Ubuntu 9.04, but I am getting > constraint_error, range check failed. > > I don't understand why 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. Either pass the value directly to the put routine -- put (integer_address'image(... -- or (probably less useful to you?) use a declare block: declare str : constant string :=3D integer_address'image(.... begin put(str);