I am having a problem while writing a package for doubly circular linked lists in ada. I am specifically writing a function that will take my DCLL and return the contents of it in array form. In my spec file I created the type like this
type ListArray is array(Integer range <>) of Integer;
My problem is, I keep getting "length check failed" errors when the client calls my package. Here is the client program(part)
procedure tester is
LL : sorted_list.List;
larray : sorted_list.ListArray(1..sorted_list.length(LL));
begin
sorted_list.Insert(LL, 5);
larray:= sorted_list.toArray(LL);
end;
I know this is failing because when I define larray and set it to the length, the length is 0 because LL doesn't have anything in it yet. In java I would just initialize the array in the body of the code after the insertion but it seems in ada I cannot do that (or at least I don't know how) Is there anyway to create an array in ada without defining the bound and then define the bounds in the body after insertion?
I hope I have explained my problem well enough for you to understand. Thanks.
ListArrayand usenewto allocate it dynamically. But you don't need to, because you can declare a variable-size array as I demonstrate in my answer, and the array will automatically be deallocated when you leave the block. - ajbmallocin C++? Tsk, tsk. - ajb