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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1fd537a3da8a5021 X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: Re: Array access via pointer? Date: 2000/08/02 Message-ID: <_TNh5.1285$nT.135157@news.pacbell.net>#1/1 X-Deja-AN: 653487734 References: <398721AD.CAEE3A51@home.com> X-Complaints-To: abuse@pacbell.net X-Trace: news.pacbell.net 965192314 24.20.190.201 (Tue, 01 Aug 2000 21:58:34 PDT) Organization: SBC Internet Services NNTP-Posting-Date: Tue, 01 Aug 2000 21:58:34 PDT Newsgroups: comp.lang.ada Date: 2000-08-02T00:00:00+00:00 List-Id: 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));