views:

130

answers:

1

I need an array of 820 zeros for using with a mathematical function.

In C I could just write the following and the compiler would fill the array:

 const float EMPTY_NUMBER_A[820] = { 0.0, };

However in Ada that isn't possible. I really don't want to hard code the 820 elements as 0.0. Is there a way to get the compiler to do it?

 type Number_A is array (1 .. 820) of Float;
 EMPTY_NUMBER_A : constant Number_A := ???;

Using Ada 95 and GNAT.

+5  A: 

Use an aggregate:

Empty_Number_A : constant Number_A := (others => 0.0);
Marc C
Much more concise then my 41 lines each of 20 zeros.
mat_geek
This is very powerful btw. If you want to set everything but element 20 to 0, you can do `(20 => 17.5, others => 0.0)`
T.E.D.
Also, you could say `(others => Ada.Numerics.Float_Random.Random (Gen))` to fill with random Floats. You have to have set up the generator `Gen` first, of course.
Simon Wright
Thanks Simon, that tip will simplify a lot of my code.
mat_geek
1 vote up. This is of the facilities of the Ada language that's motivating me to switch from C to Ada.
yCalleecharan