小编Mic*_*ley的帖子

Ada类型声明语义

我在大学读Ada.今天我的教授向我们提出了一个问题.在下面的代码中有三种类型声明.第三个没有编译错误'缺少新'.

我假设'Type'关键字让编译器知道我们要定义一个存储类,所以我的问题是:

声明之间的语义差异是什么?
如果省略关键字Integer,Ada会在指定范围时采用通用整数类型吗?这似乎是一个明显而合乎逻辑的结果.此外,当关键字'Integer'在'range'之前是新的然后是必需的?

我希望这不是模棱两可的,我做了一些研究,但似乎无法找到一个确切的答案,或者我可能与Ada的新手很多,以了解我发现了什么.我真的很想了解下面发生的事情.

with Ada.Text_IO; use ada.Text_IO;
    procedure any is
    type abc is new Integer range 1..10;
    num : abc;
    type def is range 1..10;
    num2 : def;
    type xyz is Integer range 1..10;
    num3 : xyz;
      begin
      num := 5;
      num2 := 6;
      num3 := 7;
 end any;
Run Code Online (Sandbox Code Playgroud)

types compiler-errors declaration ada subtype

1
推荐指数
1
解决办法
275
查看次数

标签 统计

ada ×1

compiler-errors ×1

declaration ×1

subtype ×1

types ×1