comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Memory Access
Date: Mon, 7 Nov 2011 14:42:53 -0800 (PST)
Date: 2011-11-07T14:42:53-08:00	[thread overview]
Message-ID: <8798b68d-b016-47e6-9cf5-326b166bf132@u10g2000prm.googlegroups.com> (raw)
In-Reply-To: 49f9578c-6f67-4af0-93b0-63120bfe23df@x28g2000prb.googlegroups.com

On Nov 7, 2:21 pm, Adam Beneschan <a...@irvine.com> wrote:
>
> If you known the address of the array data, then something like this
> will work even if you don't know the address until runtime:
>
>     Data_Address : System.Address;
>     ...
> begin
>     -- do some stuff that sets Data_Address to the address.  Or you
>     -- could make
>     -- Data_Address be a parameter to a subroutine, or something
>     -- Then:
>
>     declare
>        Dev_Table : Dev_Table_Type (1 .. Num_Devs_Cnst);
>        for Dev_Table'Address use Data_Address;
>     begin
>        -- and you can use Dev_Table in here
>     end;
>
> This will work whether Num_Devs_Cnst is known at compile time or not.
> (The _Cnst makes it look like it's a constant that's known at compile
> time.  But it doesn't need to be.)

An alternative, if you don't want to use an Address clause:

with System.Address_To_Access_Conversions;

...
   Data_Address : System.Address;
begin
   -- set Data_Address to something as above
   declare
      subtype Constrained_Dev_Table is Dev_Table_Type (1 ..
Num_Devs_Cnst);
      package Dev_Table_Pointer is new
         System.Address_To_Access_Conversions (Constrained_Dev_Table);
      Dev_Table : Dev_Table_Pointer.Object_Pointer :=
         Dev_Table_Pointer.To_Pointer (Data_Address);
   begin
      ...
   end;

Dev_Table is now declared as an access (pointer) to a constrained
array subtype, rather than an array, but you should still be able to
use it in the same way.  This method still won't let you create a
Dev_Table_Ptr_Type that points to the array, though.

                       -- Adam



  reply	other threads:[~2011-11-07 22:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-07 20:09 Memory Access awdorrin
2011-11-07 21:26 ` Simon Wright
2011-11-07 22:03 ` anon
2011-11-07 22:21 ` Adam Beneschan
2011-11-07 22:42   ` Adam Beneschan [this message]
2011-11-07 23:13   ` Simon Wright
2011-11-07 23:32     ` Adam Beneschan
2011-11-08 12:22       ` awdorrin
2011-11-08 16:00         ` Adam Beneschan
2011-11-08 17:46           ` awdorrin
2011-11-08 20:11             ` Adam Beneschan
2011-11-08 20:24               ` awdorrin
2011-11-09 14:42                 ` awdorrin
2011-11-08 16:10         ` awdorrin
2011-11-08 18:33           ` Simon Wright
2011-11-08 18:34             ` Simon Wright
2011-11-08 20:18             ` awdorrin
2011-11-08 12:44       ` Simon Wright
2011-11-07 22:26 ` Niklas Holsti
2011-11-07 22:53   ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox