Re: Records that could be arrays



Dmitry A. Kazakov wrote:
... The rest is a question of language deficiency. In this case an
inability to provide an array interface to a record type (to have
enumerated components), or a record interface to an array (to have named
components.) ...

I'm not sure what you mean by a language deficiency. If you really
want to address an object as either a record or an array, doesn't
something like this meet your needs?

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Redefine is

type IntRecord is
record
FirstInt : Integer;
SecondInt : Integer;
end record;
type IntArray is
array (1 .. 2) of Integer;

RecVar : IntRecord := (FirstInt => 1, SecondInt => 2);

ArrayVar : IntArray;
for ArrayVar'Address
use RecVar'Address;

begin

Put("First Record Element = ");
Put(RecVar.FirstInt);
New_Line;
Put("Array Element 2 = ");
Put(ArrayVar(2));
New_Line;

end Redefine;

.



Relevant Pages