Sorry if it’s a really basic question. Im looking for a way to get the sum of entire array in compilation time to avoid Ravenscar profile “No_Implicit_Heap_Allocation” restriction
the “problematicVariable” raises a “No_Implicit_Heap_Allocation_Error”.
the “NoproblemVariable” is working… but need a lot of mechanical work…specially becouse the type MyLargeEnumerationtype could grow until thousands of elements…
¿Any ideas for a solution that will not need to write every element of the enumeration in the sum?
Here is the code:
pragma Profile (Ravenscar);
package Constants is
type MyLargeEnumerationtype is ( e1, e2, e3);
type MyBoringTableType is array (MyLargeEnumerationtype) of Natural;
M : constant MyBoringTableType :=
( e1 => 5,
e2 => 8,
e3 => 11);
Sum_Of_Boring_Table : constant Natural :=
(M (e1) + M(e2) + M(e3));
function FunctionSum return Natural;
end Constants;
package body Constants is
function FunctionSum return Natural is
Sum : Natural := 0;
begin
for I in M'Range loop
Sum := Sum + M(I);
end loop;
return Sum;
end FunctionSum;
end Constants;
pragma Profile (Ravenscar);
with constants; use constants;
package test is
type KnowedSizetype is array ( 1 .. Sum_OF_Boring_Table) of Natural;
type notknowedSizeType is array ( 1 .. functionsum) of Natural;
NoproblemVariable : KnowedSizetype;
ProblematicVariable : notknowedSizeType;
end test;