I'd be very surprised if you got a compile-time Storage_Error on that code.
I've grabbed a copy of your code and modified it as follows; it compiles without error using GNAT (gcc-4.4):
procedure Array_2D is type UnconstrainedArray_2D is array (Integer range <>, Integer range <>) of Integer; function temp(tempIn : in Integer; Table : in UnconstrainedArray_2D) return Integer is tempTable : UnconstrainedArray_2D(0..tempIn, 0..tempIn); begin for i in 0..tempTable'last(1) loop for j in 0..tempTable'last(2) loop tempTable(i, j) := Table(i,j); end loop; end loop; return 42; -- added this end temp; begin null; end Array_2D;
(Note that I had to add the missing return statement in temp.)
Your syntax for the 'Last attribute (not "command") is correct, but since Ada arrays can have arbitrary lower and upper bounds, it's better to use the 'Range attribute instead:
for i in tempTable'Range(1) loop for j in tempTable'Range(2) loop tempTable(i, j) := Table(i,j); end loop; end loop;
As for the Storage_Error exception, that could easily happen at run time (not compile time) if you call your temp function with a very large value for tempIn. Remember that it has to allocate enough space to hold tempIn**2 Integer objects. Presumably you've also created another UnconstrainedArray_2D object to be passed in as the Table parameter.
It's conceivable that the compiler itself could die with a Storage_Error exception, but I don't see anything in your code that might cause that.
Show us a complete (but small) program that demonstrates the problem you're having, along with the exact (copy-and-pasted) error message. Please distinguish clearly between compile-time and run-time errors.
Table : in UnconstrainedArray_2Din the function. But I'm still not sure what I have done wrong.