Ada: Null exclusion in arrays holding pointers

Viewed 114

I was trying to use null excluded arrays holding access types in Ada. Example:

type Integer_Access is access all Integer;
type MyArr is array (1 .. 2) of not null Integer_Access;

My compiler keeps warning me that a Costraint_Error may be thrown at runtime (only by declaring this type, without instantiation). Is declaring such an array illegal (or bad practice)?

1 Answers

Access types are initialized to null (see the ARM and the rational). When declaring a variable of this type, it would be initialized with null values which is forbidden by the type itself.

On my side, I get the message:

access_array.adb:6:04: warning: (Ada 2005) null-excluding objects must be initialized
access_array.adb:6:04: warning: "Constraint_Error" will be raised at run time

From my point of view, the only way to deal with this is to provide some kind of constructor.

Related