Next: , Up: Code Generation for Array Aggregates


12.4.1 Static constant aggregates with static bounds

For the declarations:

         type One_Dim is array (1..10) of integer;
         ar0 : constant One_Dim := ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 0);

GNAT generates no executable code: the constant ar0 is placed in static memory. The same is true for constant aggregates with named associations:

         Cr1 : constant One_Dim := (4 => 16, 2 => 4, 3 => 9, 1=> 1);
         Cr3 : constant One_Dim := (others => 7777);

The same is true for multidimensional constant arrays such as:

         type two_dim is array (1..3, 1..3) of integer;
         Unit : constant two_dim := ( (1,0,0), (0,1,0), (0,0,1));

The same is true for arrays of one-dimensional arrays: the following are static:

     type ar1b  is array (1..3) of boolean;
     type ar_ar is array (1..3) of ar1b;
     None  : constant ar1b := (others => false);     --  fully static
     None2 : constant ar_ar := (1..3 => None);       --  fully static

However, for multidimensional aggregates with named associations, GNAT will generate assignments and loops, even if all associations are static. The following two declarations generate a loop for the first dimension, and individual component assignments for the second dimension:

     Zero1: constant two_dim := (1..3 => (1..3 => 0));
     Zero2: constant two_dim := (others => (others => 0));