Ada83 Constraint Error not Present in Watch Window

49 views Asked by At

I'm looking at a constraint error when running this code. In the debugger it halts on the 2nd line (Menu_Text...). I put the code on the RHS of the assignment into the watch window and I see no problem. It's evaluates exactly as it should.

     for I in 1..This_Info_Ptr.Child_Menu_Length loop
        Menu_Text  := This_Info_Ptr.Child_Menu_Text_Ptr.all(I-1);
        Menu_State := This_Info_Ptr.Child_Menu_States_Ptr.all(I-1);
        ...

The error is when I is 1. I have confirmed that this code works in the watch window:

This_Info_Ptr.Child_Menu_Text_Ptr.all(I-1)

Child_Menu_Text_Ptr and Child_Menu_States_Ptr point to arrays (of strings and enums),

How should I debug this I general? I can't see anything wrong with the code. However, my familiarity with Ada access types is limited. The ..._Ptr variables are access types.

I am using GNAT.

2

There are 2 answers

0
NWS On BEST ANSWER

Assuming the arrays being indexed are all of the same dimension and have the same index type, then iterating over them should be done using the 'first & 'last or 'range attributes.

It is likely that the hand coded control of length values has a bug. Using the inbuilt functionality is safer and more reliable.

0
Jacob Sparre Andersen On

You aren't showing enough source text to tell us for sure what is happening. IsThis_Info_Ptr.Child_Menu_Text_Ptr.all a function or an array? What is it's specification?

If it is an array, you should remember that Ada allows arrays to be indexed by any discrete type, and that arrays in Ada always know their own indexing bounds.