[英]Ada, check out my package. ("compilation unit expected"?)
我已經擺脫了所有其他編譯時錯誤,除了“預期的編譯單元”,它在我的導入語句之后立即開始。 我猜我需要創建一個包? 如果是這樣,我該怎么做? 我有幾個函數都位於同一個 .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"
馬克西姆斯
這些編譯器消息不能屬於您發布的代碼(因為它沒有28行)。
無論如何,GCC都希望此代碼位於mypackage.adb
文件中; 並要求mypackage.ads
有一個軟件包規格。
有同樣的錯誤我忘記了它是如何工作的所以經過一些試驗和錯誤我發現
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;
順便說一句,這與包無關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.