艾达,看看我的包裹。 (“预期的编译单元”?)

发布于 2024-10-08 11:25:04 字数 543 浏览 0 评论 0原文

我已经摆脱了所有其他编译时错误,除了“预期编译单元”,它在我的导入语句之后开始。我猜我需要创建一个包?如果是这样,我该怎么做?我有几个函数都位于同一个 .ADB 文件中。

编辑:所以我试了一下...

查看我的包:

-- Import Statements
with Ada.Text_Io;
use Ada.Text_Io;

package body MyPackage is

-- Declarations
-- Functions

end MyPackage;

但是 gcc 在看到 MyPackage 时尖叫:

a_.adb:27:18: loop or block statement must follow label
a_.adb:27:18: reserved word "array" cannot be used as identifier
a_.adb:28:01: declarations must come before "begin"

Maximus graCimuS

I've gotten rid of all my other compile-time errors except "compilation unit expected", which starts right after my import statements. I'm guessing I need to create a package? And if so, how do I do it? I have a few functions all living in the same .ADB file.

EDIT: So I gave it a shot...

Check out my package:

-- Import Statements
with Ada.Text_Io;
use Ada.Text_Io;

package body MyPackage is

-- Declarations
-- Functions

end MyPackage;

But gcc screams when it sees MyPackage:

a_.adb:27:18: loop or block statement must follow label
a_.adb:27:18: reserved word "array" cannot be used as identifier
a_.adb:28:01: declarations must come before "begin"

Maximus graCimuS

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与风相奔跑 2024-10-15 11:25:04

包体是包规范的实现。

无意冒犯,但您需要熟悉一些基本的 Ada 编程概念。

也许可以从 Lovelace 教程开始,它是一个老东西,但却是一个好东西。

A package body is the implementation of a package specification.

No offense, but you need to familiarize yourself with some basic Ada programming concepts.

Maybe start with Lovelace Tutorial, it's an oldie but a goodie.

2024-10-15 11:25:04

这些编译器消息不能属于您发布的代码(因为它没有 28 行)。

无论如何,GCC 都会期望此代码位于文件 mypackage.adb 中;并要求 mypackage.ads 中有一个软件包规范。

Those compiler messages can't belong to the code you posted (because it doesn't have 28 lines).

In any case, GCC will expect this code to be in a file mypackage.adb; and will require there to be a package spec in mypackage.ads.

羞稚 2024-10-15 11:25:04

有同样的错误,我忘记了它是如何工作的,所以经过一些尝试和错误后,我发现

WITH Ada.Text_IO;
USE Ada.Text_IO;
WITH Ada.Integer_Text_Io;
USE Ada.Integer_Text_IO;
WITH Ada.Float_Text_IO;
USE Ada.Float_Text_IO;
--ecrire(x) lire(x) put(x) get(x);
--errors handling
WITH Ada.IO_Exceptions;


--Additionnal log functions alike
WITH Ada.Numerics.Elementary_Functions;
USE Ada.Numerics.Elementary_Functions;

--  WITH Ada.Text_Io;
--  USE Ada.Text_Io;
--  WITH Ada.Integer_Text_Io;
--  USE Ada.Integer_Text_Io;

procedure remplit is

   type tablo is array(1.. 5) of float;
   

Procedure toto ( Init : in float ; T : out tablo ) is

Begin

For I in T'first + 1..T'last loop
      T(i) := Init * float(i);
      put(t(i));
   End loop;

   End toto;
   
   T : tablo;
   
begin
   toto(1.5, T);
   
   end remplit;

而不是产生这个错误......

WITH Ada.Text_IO;
USE Ada.Text_IO;
WITH Ada.Integer_Text_Io;
USE Ada.Integer_Text_IO;
WITH Ada.Float_Text_IO;
USE Ada.Float_Text_IO;
--ecrire(x) lire(x) put(x) get(x);
--errors handling
WITH Ada.IO_Exceptions;


--Additionnal log functions alike
WITH Ada.Numerics.Elementary_Functions;
USE Ada.Numerics.Elementary_Functions;

--  WITH Ada.Text_Io;
--  USE Ada.Text_Io;
--  WITH Ada.Integer_Text_Io;
--  USE Ada.Integer_Text_Io;



   type tablo is array(1.. 5) of float;
   

Procedure remplit ( Init : in float ; T : out tablo ) is

Begin

For I in T'first + 1..T'last loop
      T(i) := Init * float(i);
      put(t(i));
   End loop;


   
   end remplit;

顺便说一句,它与包无关。

Had same error I forgot how it works so after some trial and error I found

WITH Ada.Text_IO;
USE Ada.Text_IO;
WITH Ada.Integer_Text_Io;
USE Ada.Integer_Text_IO;
WITH Ada.Float_Text_IO;
USE Ada.Float_Text_IO;
--ecrire(x) lire(x) put(x) get(x);
--errors handling
WITH Ada.IO_Exceptions;


--Additionnal log functions alike
WITH Ada.Numerics.Elementary_Functions;
USE Ada.Numerics.Elementary_Functions;

--  WITH Ada.Text_Io;
--  USE Ada.Text_Io;
--  WITH Ada.Integer_Text_Io;
--  USE Ada.Integer_Text_Io;

procedure remplit is

   type tablo is array(1.. 5) of float;
   

Procedure toto ( Init : in float ; T : out tablo ) is

Begin

For I in T'first + 1..T'last loop
      T(i) := Init * float(i);
      put(t(i));
   End loop;

   End toto;
   
   T : tablo;
   
begin
   toto(1.5, T);
   
   end remplit;

instead of this that produce this error...

WITH Ada.Text_IO;
USE Ada.Text_IO;
WITH Ada.Integer_Text_Io;
USE Ada.Integer_Text_IO;
WITH Ada.Float_Text_IO;
USE Ada.Float_Text_IO;
--ecrire(x) lire(x) put(x) get(x);
--errors handling
WITH Ada.IO_Exceptions;


--Additionnal log functions alike
WITH Ada.Numerics.Elementary_Functions;
USE Ada.Numerics.Elementary_Functions;

--  WITH Ada.Text_Io;
--  USE Ada.Text_Io;
--  WITH Ada.Integer_Text_Io;
--  USE Ada.Integer_Text_Io;



   type tablo is array(1.. 5) of float;
   

Procedure remplit ( Init : in float ; T : out tablo ) is

Begin

For I in T'first + 1..T'last loop
      T(i) := Init * float(i);
      put(t(i));
   End loop;


   
   end remplit;

Btw it's not about packages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文