3

I've having trouble with package visibility. I have a really simple package and the code is listed below. The error message is shown here:

viterbi.adb:12:14: "Integer_Text_IO" is not visible (more references follow)
viterbi.adb:12:14: non-visible declaration at a-inteio.ads:18
gnatmake: "viterbi.adb" compilation error

The package specification is as follows:

package Viterbi is

  procedure Load_N_File(
    Filename : in String;
    N : in out Integer;
    M : in out Integer);

end Viterbi;

The package body is as follows:

with Ada.Integer_Text_IO; use with Ada.Integer_Text_IO;
with Ada.Strings; use Ada.Strings;

package body Viterbi is

  procedure Load_N_File(
    Filename : in String;
    N : in out Integer;
    M : in out Integer
  ) is
    N_File : File_Type;
  begin
    Open( N_File, Mode=>In_File, Name=>Filename );
    Get( N_File, N ); 
    Get( N_File, M );
    Close( N_File ); 
  end Load_N_File;

end Viterbi;

What in my package body is causing the package to stay hidden? Shouldn't the use clause bring Integer_Text_IO into view?

Dr. Watson
  • 3,752
  • 4
  • 32
  • 43
  • Many disagree with me, but I generally advise folks to write their code first without any `use` clauses. When its done and you get to the cleanup phase, then you can put them back in if it makes the code clearer. The problem with them is that they allow you to be lazy to the point where you get issues like the above where you are pulling your hair out because you think things are in packages that they are not actually in. – T.E.D. Feb 07 '11 at 14:20
  • That actually seems very reasonable. When I write C++, I always use full scoping (i.e. boost::smarter_ptr, std::string) except in the very top module. I think it makes sense to adopt such a policy in Ada too. – Dr. Watson Feb 07 '11 at 19:17
  • What compiler are you using? I get "viterbi.adb:1:31: reserved word "with" cannot be used as identifier"! – Simon Wright Feb 17 '11 at 14:25
  • I am using GNAT for Linux x86_64. I'm not at work right now so I don't know the version number. But I downloaded it from the Libre website this past autumn. – Dr. Watson Feb 18 '11 at 06:15

2 Answers2

5

The code of the package body as provided has a syntax error: the spurious "with" in the "use with Ada.Integer_Text_IO;" clause.

Having fixed that, I then get compilation errors revolving around the inability to resolve File_Type, Open, and Close. Adding a "with" and "use" of Ada.Text_IO gives me a clean compilation.

So the start of the package body looks like:

with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Strings; use Ada.Strings;
with Ada.Text_IO; use Ada.Text_IO;

package body Viterbi is
   ...

If you're still getting a "can't find Integer_Text_IO" error after fixing these errors, then I'd be suspicious about your development environment, i.e. is everything installed correctly?

Marc C
  • 8,664
  • 1
  • 24
  • 29
  • Thank you, I cannot believe I missed the extra "with". Removing it did not make the error go away, but adding the Ada.Text_IO package and bringing it into view resolved the error. Thanks again. – Dr. Watson Feb 07 '11 at 04:56
2

You can avoid the "use with" style of error, as already pointed out, by using the comma-separated style: With -- Testing, Ada.Integer_Text_IO, Ada.Strings;

Use
-- Testing,
Ada.Strings,
Ada.Integer_Text_IO;

this also allows you to comment out specific package 'withs' or 'usues' as shown.

Shark8
  • 4,095
  • 1
  • 17
  • 31
  • Nice, I didn't know you could separate the package names with a comma. I really need to get around to reading the language spec on of these days... – Dr. Watson Feb 18 '11 at 06:18