为什么此代码不生成约束错误或打印正数?
Why doesn't this code generate a constraint error or print a positive number?
我希望此代码生成约束错误或打印正数。为什么这段代码两者都不做?
with Ada.Text_IO;
use Ada.Text_IO;
procedure Overflow is
procedure P (I : Positive) is
X : Integer := Integer'Last;
begin
X := (X + I) / 2;
Put_Line (Integer'Image (X) & " should be positive");
end;
begin
P(10);
end;
可能是因为您的编译器未配置为作为正确的 Ada 编译器工作。具体来说,旧版本的 GNAT 需要一个标志才能作为适当的 Ada 编译器工作。根据我的笔记,标志是:
-fstack-check -gnata -gnato
我希望此代码生成约束错误或打印正数。为什么这段代码两者都不做?
with Ada.Text_IO;
use Ada.Text_IO;
procedure Overflow is
procedure P (I : Positive) is
X : Integer := Integer'Last;
begin
X := (X + I) / 2;
Put_Line (Integer'Image (X) & " should be positive");
end;
begin
P(10);
end;
可能是因为您的编译器未配置为作为正确的 Ada 编译器工作。具体来说,旧版本的 GNAT 需要一个标志才能作为适当的 Ada 编译器工作。根据我的笔记,标志是:
-fstack-check -gnata -gnato