我创建了以下示例:
procedure Example is
type Index_Type is range 1 .. 3;
type Array_Type is array (Index_Type) of Integer;
Array_Fail_One : Array_Type := (11, 22, 33, 44);
Array_Fail_Two : Array_Type := (1 => 11, 2 => 22, 3 => 33, 4 => 44);
begin
null;
end Example;
为什么这种问题只被视为警告而不是错误?
example.adb:6:35: warning: upper bound of aggregate out of range
example.adb:6:35: warning: Constraint_Error will be raised at run time
example.adb:7:35: warning: upper bound of aggregate out of range
example.adb:7:35: warning: Constraint_Error will be raised at run time
最佳答案
这是一个警告,因为编译器检测到运行时错误,这将导致引发异常 Constraint_Error。
Ada 编译器不保证不存在所有运行时错误,但它会标记它检测到的那些错误。
关于ada - 数组元素过多仅编译器警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64825314/