From: sjw <simon.j.wright@mac.com>
Subject: Re: put of access type
Date: Wed, 19 Aug 2009 12:44:03 -0700 (PDT)
Date: 2009-08-19T12:44:03-07:00 [thread overview]
Message-ID: <68e68a01-eca6-4f17-9496-cc5d2eee7113@k26g2000vbp.googlegroups.com> (raw)
In-Reply-To: 8sho8596j3qnja38id9ipejk0opkcn5b5m@4ax.com
On Aug 19, 8:00 pm, Rob Solomon <use...@drrob1-noreply.com> wrote:
> >> I would like to output a pointer to the screen. (I am just learning
> >> Ada).
>
> >> How do I put(Any_Access_Type)
>
> >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).
> I need help with this code:
>
> procedure adr is
>
> c: integer;
> x: aliased integer;
> p1, p2 : access integer;
> str : string (1..255);
>
> Begin
> p1 := x'access;
> p2 := p1;
> str := integer_address'image(to_integer(p1.all'address));
> c := 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 := integer_address'image(....
begin
put(str);
next prev parent reply other threads:[~2009-08-19 19:44 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-18 22:26 put of access type Rob Solomon
2009-08-18 23:17 ` Jeffrey R. Carter
2009-08-19 3:36 ` Rob Solomon
2009-08-19 7:44 ` Jean-Pierre Rosen
2009-08-20 8:06 ` Stephen Leake
2009-08-19 11:16 ` Robert A Duff
[not found] ` <k_2dncb9WoxvFRbXnZ2dnUVZ_jmdnZ2d@earthlink.com>
2009-08-20 8:05 ` Stephen Leake
2009-08-20 15:42 ` Adam Beneschan
2009-08-21 8:24 ` Stephen Leake
2009-08-19 6:25 ` Martin Krischik
2009-08-19 7:21 ` Dmitry A. Kazakov
2009-08-19 19:00 ` Rob Solomon
2009-08-19 19:44 ` sjw [this message]
2009-08-20 1:54 ` Rob Solomon
2009-08-20 2:06 ` Rob Solomon
2009-08-20 15:18 ` (see below)
2009-08-19 21:01 ` Adam Beneschan
2009-08-19 22:45 ` Randy Brukardt
2009-08-20 6:18 ` Martin Krischik
2009-08-21 0:18 ` Randy Brukardt
2009-08-21 1:20 ` Adam Beneschan
2009-08-21 14:47 ` Robert A Duff
2009-08-21 21:43 ` Randy Brukardt
2009-08-22 0:07 ` Robert A Duff
2009-09-01 1:57 ` Randy Brukardt
2009-08-20 6:08 ` Martin Krischik
2009-08-20 20:57 ` Robert A Duff
2009-08-20 6:01 ` Martin Krischik
2009-08-20 17:54 ` tmoran
2009-08-31 7:08 ` Martin Krischik
2009-08-20 18:58 ` Dmitry A. Kazakov
2009-08-20 22:27 ` sjw
2009-08-21 7:29 ` Dmitry A. Kazakov
2009-08-21 21:09 ` sjw
2009-08-31 7:12 ` Martin Krischik
2009-08-20 20:29 ` Robert A Duff
2009-08-21 8:18 ` Stephen Leake
2009-08-21 14:31 ` Robert A Duff
2009-08-21 14:41 ` Robert A Duff
2009-08-22 12:02 ` Stephen Leake
2009-08-20 8:09 ` Stephen Leake
[not found] ` <GoydnWoDmpUW4BDXnZ2dnUVZ_rKdnZ2d@earthlink.com>
2009-08-21 8:31 ` Stephen Leake
2009-08-21 8:42 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox