comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Memory Access
Date: Mon, 7 Nov 2011 14:21:44 -0800 (PST)
Date: 2011-11-07T14:21:44-08:00	[thread overview]
Message-ID: <49f9578c-6f67-4af0-93b0-63120bfe23df@x28g2000prb.googlegroups.com> (raw)
In-Reply-To: f4a52e5d-2514-4713-a68d-877f09af7ec3@d17g2000yql.googlegroups.com

On Nov 7, 12:09 pm, awdorrin <awdor...@gmail.com> wrote:

> I would have thought I could have defined the Dev_Table differently,
> perhaps:
>
> Dev_Table : Dev_Table_Ptr_Type := new Dev_Table_Type( 1 ..
> Num_Devs_Cnst );
>
> If I knew the address of pointer at the time of declaration I figured
> I could do:
>
> for Dev_Table'Address use {address_of_memory_array} - but I won't know
> that until run time, so I'm not sure how I can assign that properly.

I'm not 100% clear on what you're trying to do.  First of all, what
will you have at runtime: the address of the array (i.e. the address
of the first element of the array), or the address of a POINTER to the
array (i.e. the address of a word that contains the address of the
first element of the array)?  Your code above will declare Dev_Table
to be a pointer, and then the "for ... use" clause will tell it what
the address of the POINTER will be--not the address of the data in the
array.

I'm assuming that isn't what you want.

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.)

You can use Dev_Table inside the begin..end block, and you can pass it
as a parameter to subroutines that take an unconstrained
Dev_Table_Type parameter.  However, I don't think there's a portable
way to declare a Dev_Table_Ptr_Type, which is an access to an
unconstrained array, and set it up so that it points to an array at
Data_Address with bounds 1 and Num_Dev_Cnst.  The Ada language
restricts this because I don't think it's possible to make this work
in every implementation, depending on how access-to-unconstrained-
array types are implemented.  Hopefully you won't need the pointer
type, and the example I gave is good enough for you to use.

                              -- Adam





  parent reply	other threads:[~2011-11-07 22:23 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 [this message]
2011-11-07 22:42   ` Adam Beneschan
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