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-7-bit Received: by 10.68.50.169 with SMTP id d9mr1296218pbo.0.1320707587134; Mon, 07 Nov 2011 15:13:07 -0800 (PST) Path: h5ni10291pba.0!nntp.google.com!news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Memory Access Date: Mon, 07 Nov 2011 23:13:06 +0000 Organization: A noiseless patient Spider Message-ID: References: <49f9578c-6f67-4af0-93b0-63120bfe23df@x28g2000prb.googlegroups.com> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="25892"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SIVfI4o6Uil9SAGd9vlkgurDaShQVaUg=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:nsH7YcFTd+RKn2yjkXDROpUkANI= sha1:FFuqGESuxgT8FFLRaIP0XVAQERs= Xref: news1.google.com comp.lang.ada:18848 Content-Type: text/plain; charset=us-ascii Date: 2011-11-07T23:13:06+00:00 List-Id: Adam Beneschan writes: > 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; One thing to be wary of here is that Dev_Table might contain initialised components. type Integer_P is access all integer; type Rec is record I : Integer_P; end record; R : Rec; for R'Address use ...; may well get R.I initialised to null. I don't know whether it's a GNAT convention, but the way to avoid this in GNAT is to add pragma Import (Ada, R); The other thing is, you could declare an array type as large as you like - in a package body - and provide access subprograms, something like with Ada.Text_IO; use Ada.Text_IO; with System; procedure Devs is type Config_Type is record Name : String (1 .. 4); Size : Natural; end record; pragma Convention (C, Config_Type); Max_Devices : constant := 1024; type Device_Index is range 1 .. Max_Devices; type Dev_Table_Type is array (Device_Index range <>) of Config_Type; pragma Convention (C, Dev_Table_Type); -- Set up at initialization Dev_Table_Address : System.Address; Number_Of_Devices : Device_Index; procedure Set_Size (For_Device : Device_Index; To : Natural) is Dev_Table : Dev_Table_Type (1 .. Number_Of_Devices); for Dev_Table'Address use Dev_Table_Address; pragma Import (Ada, Dev_Table); begin Dev_Table (For_Device).Size := To; end Set_Size; function Name (Of_Device : Device_Index) return String is Dev_Table : Dev_Table_Type (1 .. Number_Of_Devices); for Dev_Table'Address use Dev_Table_Address; pragma Import (Ada, Dev_Table); begin return Dev_Table (Of_Device).Name; end Name; Devs : Dev_Table_Type (1 .. 2) := (("aaaa", 21), ("bbbb", 42)); begin Dev_Table_Address := Devs'Address; Number_Of_Devices := Devs'Length; Put_Line (Name (Of_Device => 2)); Put_Line (Name (Of_Device => 3)); -- raises Constraint_Error end Devs;