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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7f18265ce67560b3 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.35.68 with SMTP id f4mr1080916pbj.5.1320774396514; Tue, 08 Nov 2011 09:46:36 -0800 (PST) Path: h5ni13362pba.0!nntp.google.com!news2.google.com!postnews.google.com!o14g2000yqh.googlegroups.com!not-for-mail From: awdorrin Newsgroups: comp.lang.ada Subject: Re: Memory Access Date: Tue, 8 Nov 2011 09:46:36 -0800 (PST) Organization: http://groups.google.com Message-ID: <91ebbfff-9108-4401-9056-963db3f12f9e@o14g2000yqh.googlegroups.com> References: <49f9578c-6f67-4af0-93b0-63120bfe23df@x28g2000prb.googlegroups.com> <35c7e403-6503-4e26-8764-9783caf84871@e2g2000vbb.googlegroups.com> NNTP-Posting-Host: 192.91.147.34 Mime-Version: 1.0 X-Trace: posting.google.com 1320774396 28986 127.0.0.1 (8 Nov 2011 17:46:36 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 8 Nov 2011 17:46:36 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o14g2000yqh.googlegroups.com; posting-host=192.91.147.34; posting-account=YkFdLgoAAADpWnfCBA6ZXMWTz2zHNd0j User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESRCNK X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,gzip(gfe) Xref: news2.google.com comp.lang.ada:14350 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-11-08T09:46:36-08:00 List-Id: On Nov 8, 11:00=A0am, Adam Beneschan wrote: > > You're saying that Dev_Table is a global access to an unconstrained > array, and it sounds to me like you're trying to get Dev_Table to > point to some arbitrary address that isn't known until runtime. > Unfortunately, I don't think there's a portable way to do that in Ada > (because the implementation of unconstrained arrays differs between > implementations). =A0In fact, there may not be a good way to do it at > all in GNAT, even non-portably. > > A possibility is to make Dev_Table an access to a *constrained* > array. =A0If Num_Devs_Cnst is a constant that is known at compile time, > you could declare > > =A0 subtype Constrained_Dev_Table is Dev_Table_Type (1 .. > Num_Devs_Cnst); > =A0 type Dev_Table_Ptr_Type is access all Constrained_Dev_Table; > > and now there are a couple ways to make Dev_Table_Ptr_Type point to > what you want. =A0Here's one, based on an example I gave earlier: > > =A0 =A0with System.Address_To_Access_Conversions; > > then declare the following **globally** (not inside a subprogram): > > =A0 =A0package Dev_Table_Pointer is new > =A0 =A0 =A0 =A0 =A0System.Address_To_Access_Conversions > (Constrained_Dev_Table); > > and now, to make Dev_Table point to the data at address Dev_Data_Obj: > > =A0 =A0Dev_Table :=3D Dev_Table_Ptr_Type (Dev_Table_Pointer.To_Pointer > (Dev_Data_Obj)); > > If Num_Devs_Cnst isn't known at compile time, you could still declare > a constrained array type: > > =A0 subtype Constrained_Dev_Table is Dev_Table_Type (1 .. Integer'Last); > > and do the same as above. =A0But then you have to do extra work to make > sure that you don't later access a Dev_Table element outside the range > 1 .. Num_Devs_Cnst. =A0One way is that whenever you want to work with > Dev_Table: > > =A0 declare > =A0 =A0 =A0Actual_Dev_Table : Dev_Table_Type renames Dev_Table (1 .. > Num_Devs_Cnst); > =A0 =A0 =A0 =A0 -- or Dev_Table.all (1 .. Num_Devs_Cnst), which means the= same > thing > =A0 begin > =A0 =A0 =A0-- > =A0 =A0 =A0Something :=3D Actual_Dev_Table (NNN).Something; > =A0 =A0 =A0 =A0 -- will raise Constraint_Error if NNN is out of range 1 .= . > Num_Devs_Cnst > =A0 end; > > Hope this helps. > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- Adam Adam, Thanks - I tried your suggestion and it looks like it may be working. At least the code is no longer SegFaulting ;) Now I just have to try to understand what is actually going on with those commands. I'm assuming that the subtype is setting the bounds on the array. so that the Dev_Table_Ptr_Type is now able to see the elements. The Dev_Table_Pointer.To_Pointer is mapping the address to an access type. I'm not quite sure I understand why the package definition for Dev_Table_Pointer is needed - and why System.Address_To_Access_Conversions cannot be used directly... i'm guessing its due to Ada type checking? Thanks!