Hello,
I am trying to create a procedure that can operate on an access type of an array, in which the bounds shall be known at runtime.
In my code I am getting an error: “Object subtype must statically match designated subtype”.
with Ada.Text_IO; use Ada.Text_IO;
procedure Example is
type u8 is mod 2 ** 8;
type Pixel is record
R : u8;
G : u8;
B : u8;
end record;
type Surface_Type is array (Natural range <>) of Pixel;
type Surface_Access is access all Surface_Type;
procedure Surface_Updater (Surface : Surface_Access)
is
begin
for P in Surface'Range loop
-- Set pixel
null;
end loop;
end;
Primary : aliased Surface_Type (1 .. 1024 * 768);
begin
Surface_Updater (Primary'Access);
end Example;
I found that I could write an operationally equivalent procedure by passing System.Address and length parameters instead of an access type, but I am curious if I can use an access type and loop over the referenced array.
Thanks,
N