ada - 数组元素过多仅编译器警告?

标签 ada

我创建了以下示例:

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/

相关文章:

Ada:案例子集共享共同属性的变体记录

integer - 操作数的类型无效 "+"Ada 95

compilation - 如何与.gpr 项目文件和gprbuild 交叉编译?

ada - 子程序声明部分评估顺序 Ada

math - 在 Ada 中,有没有办法让枚举类型像模数类型一样工作——在它的最后一个范围之后换行到 0?

Ada : custom type in range 1. .var?

Ada:在公共(public)函数的前提条件中使用私有(private)变量

Ada DLL 导致 system.secondary_stack.ss_mark 中的段错误

ada - 在 Ada 中返回一个包含一个元素的数组

arrays - Ada:用可变大小的数组打包记录