【问题标题】:Can't get simple Ada Iterator example to compile无法编译简单的 Ada Iterator 示例
【发布时间】:2015-07-10 13:25:40
【问题描述】:

我正在学习 Ada,我正在尝试让一个非常简单的循环工作(使用 Ada 2012 中的新迭代器语法)。我看不出有什么问题...

with Ada.Text_IO;
use Ada.Text_IO;

procedure Arrays is
  type V is array (0 .. 1, 0 .. 2) of Natural;
  A : V := ((10, 20, 30), (400, 500, 600));
begin
  for E of A loop  --  compiler error here!
    E := E + 1;
  end loop;
end Arrays;

我的编译命令是“$ gnatmake -gnaty -gnaty2 -gnat12 arrays”(用于执行迂腐风格和启用 2012 功能)。 编译错误是

arrays.adb:8:14: too few subscripts in array reference

(我在 Raspi 上使用 gnatmake 4.6)。

这段代码是从 John Barnes 的书“Programming in Ada 2012”第 120-121 页拼凑而成的。我已经尽可能地精简了这段代码,这就是它没有做太多的原因。据我所知,它与书中的示例非常有效。

我做错了什么?

【问题讨论】:

  • 可能...使用 gcc-4.6。从那时起,对 Ada-2012 的支持有了很大的改进。 gcc-4.9 应该可用于 R-Pi 并做你想做的事。 (编辑:gnatmake 4.9 默默地吞下你的例子,制作一个可执行文件)
  • 感谢您为我调查。我的 raspi 似乎认为 4.6 仍然是 gnat 工具的最新版本。我将四处寻找是否可以从源代码手动构建 4.9。
  • Raspian 是在 Debian 上构建的(加上 Debian 本身可用于 Pi),并且 4.9 是 Debian Jessie 的标准版本,因此取决于您的发行版,它应该可用。
  • 无法在我的 Pi 上运行 4.9,可能会跳到我正确的计算机上并在那里安装最近的 Debian 发行版。感谢您的帮助。
  • 它可以使用 GNAT 2015 GPL 编译。

标签: compiler-errors iterator ada


【解决方案1】:

使用嵌套数组。

    procedure Iterator is
        type rows is array (0 .. 2) of Natural;
        type columns is array (0 .. 1) of rows;
        A : columns := ((10, 20, 30), (400, 500, 600));
    begin
        for column of A loop
            for E of column loop
                E := E + 1;
                put_line (e'img);
            end loop;
        end loop;
    end Iterator;

【讨论】:

    猜你喜欢
    • 2012-07-26
    • 2017-03-26
    • 2017-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    • 2019-05-10
    相关资源
    最近更新 更多