7.2. Multidimensional Arrays - JulTob/Ada GitHub Wiki

Multidimensional Arrays


Matrix : array (1 .. 20, 1..20) of Float;
...
Matrix := (others => (others => 0.0));
...
  for n in Matrix'Range(1) loop
    for m in Matrix'Range(2) loop
      Ada.Float_Text_IO.Put(
         Matrix(n,m), 
         Exp => 0);
      end loop;
    New_Line;
    end loop;

type Int_Matrix is array 
   (Positive range <>,
    Positive range <>)
   of Integer;

n, m: Integer := 5;
M: Int_Matrix(1..n,1..m) := (others => (others => 0));

In order to dynamically allocate the size of an array in Ada, you need to create a specific type without pre-defined sizes. The language (and the compiler as well) will not permit you to create an instance of an array type without specifying its size.