2

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

Old McStopher
  • 6,295
  • 10
  • 60
  • 89
  • These compiler errors were not present before wrapping the code with the package. – Old McStopher Dec 16 '10 at 19:35
  • 2
    Those compiler messages can't belong to the code you posted (because it doesn't have 28 lines). And GCC will expect this code to be in a file `mypackage.adb`; and will require there to be a package spec in `mypackage.ads`. – Simon Wright Dec 16 '10 at 20:46
  • Indeed, I stripped it down. And thanks for the package spec suggestion in the .ads. That may be the trick, so feel free to promote this comment to an answer. – Old McStopher Dec 16 '10 at 21:02

3 Answers3

4

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.

Marc C
  • 8,664
  • 1
  • 24
  • 29
2

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.

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
  • This is an imporant thing to note. gcc's Ada implementation takes the rather unusual step of forcing file names to match identifier names of the contents of the files. Specifically, if the file contains a package body or subroutine named `fnord`, then the file **must** (by default anyway) be named `fnord.adb`. If it contains a pacakge specification named `fnord`, then the file **must** be named `fnord.ads`. This is a quirk of gcc's gnat Ada implementation, not of Ada compilers in general – T.E.D. Dec 22 '10 at 14:01
0

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.