How would I change this code to force the indices to begin with the first index 'First evaluating to 1 and last index 'Last evaluating to 'Length ?
Menu_Text_Ptr := new Packed_Message_Array_Type'("A...",
"B...",
"C...",
"D...");
I have several dynamic arrays like this and their lengths vary. I would rather not put an explicit length of last index value because that makes code maintenance a bit more complicated. I would rather just add or subtract content from the allocation statement and let the compiler figure it out.
As it stands now, the first index 'First evaluates to -2147483648 (Which is probably something like 0x80000000).
Is it possible to do what I am asking?
This is Ada83 on GNAT.
If your first index is -2147483648 (-231), then you've probably defined your array type
Packed_Message_Array_Type
as something like:If you change the index type from
Integer
toPositive
(which is a subtype ofInteger
with a lower bound of 1), then the default lower bound will be1
.In general, if you define an array variable specifying its initial value, but not specifying the lower bound, the lower bound will default to the lower bound of the index type.
(I've deleted part of this answer; I thought you could define an index for just the first element, but positional associations cannot follow named associations.)