From: Simon Wright <simon@pushface.org>
Subject: Re: Memory Access
Date: Mon, 07 Nov 2011 23:13:06 +0000
Date: 2011-11-07T23:13:06+00:00 [thread overview]
Message-ID: <m2fwhzcyrh.fsf@pushface.org> (raw)
In-Reply-To: 49f9578c-6f67-4af0-93b0-63120bfe23df@x28g2000prb.googlegroups.com
Adam Beneschan <adam@irvine.com> 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;
next prev parent reply other threads:[~2011-11-07 23:13 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-07 20:09 Memory Access awdorrin
2011-11-07 21:26 ` Simon Wright
2011-11-07 22:03 ` anon
2011-11-07 22:21 ` Adam Beneschan
2011-11-07 22:42 ` Adam Beneschan
2011-11-07 23:13 ` Simon Wright [this message]
2011-11-07 23:32 ` Adam Beneschan
2011-11-08 12:22 ` awdorrin
2011-11-08 16:00 ` Adam Beneschan
2011-11-08 17:46 ` awdorrin
2011-11-08 20:11 ` Adam Beneschan
2011-11-08 20:24 ` awdorrin
2011-11-09 14:42 ` awdorrin
2011-11-08 16:10 ` awdorrin
2011-11-08 18:33 ` Simon Wright
2011-11-08 18:34 ` Simon Wright
2011-11-08 20:18 ` awdorrin
2011-11-08 12:44 ` Simon Wright
2011-11-07 22:26 ` Niklas Holsti
2011-11-07 22:53 ` Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox