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
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.
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
.
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.
精彩评论