Same value same type, but Constraint_Error in one case [=>another parameter was guilty]

Hi,
Here are the two procedures, Insert and Retrieve:

  procedure Insert (M: in out Matrix; N: Indexes; E: Element);
  procedure Retrieve (M: Matrix; N:Indexes; Value: out Element; Success: out Boolean);

The calls are:

Insert (M, [3,1], 87);
Retrieve (M, [1,1], Value, Success);

It is a multidimensional array implemented with a digital search tree. Insert works, the values are stored. But Retrieve doesn’t even go in the body, when running I get “Constraint_error” pointing at that line in the driver program.
Even though the type of that aggregate is the same:

type Indexes is array (Positive range <>) of Positive;

The faulty line at execution is L102 on this reproductible code.

If You change the type of the Value variable from Positive to Natural, it works.
Its because the retrieve procedure results in value=0.

1 Like

Ah yes, I didn’t think of cutting the statement in several lines to make sure the aggregate was really at fault. Thank you. I must say I don’t find digital search tree particularly useful in that case… I don’t think following a bunch of pointers is ever less expensive CPU-wise than doing simple multiplication to get from the indexes to the correct memory address. At least the exercice is interesting, the weeks passing pointers don’t frighten me like they used to.