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.9 required=5.0 tests=BAYES_00 autolearn=ham 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.30.202 with SMTP id u10mr776353pbh.1.1320768167446; Tue, 08 Nov 2011 08:02:47 -0800 (PST) Path: h5ni13071pba.0!nntp.google.com!news1.google.com!postnews.google.com!t38g2000prg.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Memory Access Date: Tue, 8 Nov 2011 08:00:49 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <49f9578c-6f67-4af0-93b0-63120bfe23df@x28g2000prb.googlegroups.com> <35c7e403-6503-4e26-8764-9783caf84871@e2g2000vbb.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1320768164 29598 127.0.0.1 (8 Nov 2011 16:02:44 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 8 Nov 2011 16:02:44 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: t38g2000prg.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: news1.google.com comp.lang.ada:18862 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-11-08T08:00:49-08:00 List-Id: On Nov 8, 4:22=A0am, awdorrin wrote: > Something like: > > declare > =A0 tempDevTable : Dev_Table_Ptr_Type :=3D new Dev_Table_Type( 1 .. > Num_Devs_Cnst ); > =A0 for tempDevTable'Address use Dev_Data_Obj; > begin > =A0 Dev_Table :=3D tempDevTable; > end > > I'm thinking this would not work - too used to C pointers I suppose > where it doesn't matter. ;) You're right: this would *not* work. Here's what the above code would do. tempDevTable is a pointer object, which may be one word or three words (or something else) depending on the implementation. This pointer *object* would be located at Dev_Data_Obj---not the pointed-to data. The "new" operation causes the program to allocate memory from a storage pool. The memory it allocates will be enough to hold Num_Devs_Cnst objects of type Config_Type. The point here is that the "new" always means to allocate memory from a storage pool; you can't use an 'Address clause to change the meaning of "new" to something else, which is what I think you were trying to do. 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). In 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. If Num_Devs_Cnst is a constant that is known at compile time, you could declare subtype Constrained_Dev_Table is Dev_Table_Type (1 .. Num_Devs_Cnst); 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. Here's one, based on an example I gave earlier: with System.Address_To_Access_Conversions; then declare the following **globally** (not inside a subprogram): package Dev_Table_Pointer is new System.Address_To_Access_Conversions (Constrained_Dev_Table); and now, to make Dev_Table point to the data at address Dev_Data_Obj: Dev_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: subtype Constrained_Dev_Table is Dev_Table_Type (1 .. Integer'Last); and do the same as above. But 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. One way is that whenever you want to work with Dev_Table: declare Actual_Dev_Table : Dev_Table_Type renames Dev_Table (1 .. Num_Devs_Cnst); -- or Dev_Table.all (1 .. Num_Devs_Cnst), which means the same thing begin -- Something :=3D Actual_Dev_Table (NNN).Something; -- will raise Constraint_Error if NNN is out of range 1 .. Num_Devs_Cnst end; Hope this helps. -- Adam