comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@bix.com
Subject: Re: Array access via pointer?
Date: 2000/08/02
Date: 2000-08-02T00:00:00+00:00	[thread overview]
Message-ID: <_TNh5.1285$nT.135157@news.pacbell.net> (raw)
In-Reply-To: 398721AD.CAEE3A51@home.com

Arr2'Address is the address of Arr2(0).  You are trying to convert
that to an access value, and not even an access to Arr2(0), but an
access to Arr2, which isn't the same thing.  So with your unchecked
conversion, you are telling the compiler that a pointer to an
element of Arr2, ie a pointer to a System.Address, is a pointer
to an Addr_Table, an array.  Since Addr_Table is unconstrained,
the compiler must store the actual bounds somewhere, so it probably
thinks your pointer points to a bounds dope vector stored at the
beginning of Arr2, when in fact it points to some System.Address value.

>A call to it might look like Foo (Arr2'Address, 7). Inside Foo, I tried
>to get at the array data in this manner:
>
>    Data := Addr_To_Ptr(Addr).all (Idx);
>where
>
>    type Addr_Table_Ptr is access Addr_Table;
>    function Addr_To_Ptr is new Unchecked_Conversion
>        (System.Address, Addr_Table_Ptr);
  An Address and an access type are not the same thing, so you are
crossing your fingers and guessing when you use Unchecked_Conversion.
Use instead predefined package System.Address_To_Access_Conversions.
(But don't try to claim a System.Address is an Addr_Table.)

>procedure Foo (Addr : in System.Address;
>               I    : in Integer) is
>begin
>    -- Do something with index I of the array at Addr
>end Foo;

   Why not

procedure Foo (Addr : in out Addr_Table;  -- both read&write access
               I    : in     Integer) is
begin
    -- Do something with index I of the array at Addr, ie, Addr(I)
end Foo;

  called with

Foo(Arr2, 7);

   or

procedure Foo (Addr : in out System.Address) is
begin
    -- Do something with Addr
end Foo;

   called with

Foo(Arr2(7));




  parent reply	other threads:[~2000-08-02  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-08-01  0:00 Array access via pointer? Michael Carman
2000-08-01  0:00 ` Ted Dennison
2000-08-02  0:00   ` Michael Carman
2000-08-03  0:00     ` Ken Garlington
2000-08-03  0:00       ` Robert A Duff
2000-08-03  0:00         ` Ken Garlington
2000-08-04  0:00           ` Robert I. Eachus
2000-08-04  0:00             ` Ken Garlington
2000-08-02  0:00 ` Markku Kotiaho
2000-08-02  0:00 ` tmoran [this message]
2000-08-02  0:00   ` Michael Carman
2000-08-02  0:00     ` tmoran
replies disabled

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