comp.lang.ada
 help / color / mirror / Atom feed
* Problem with visibility of generic package help please
@ 2003-12-11 14:03 Ute
  2003-12-11 15:15 ` Georg Bauhaus
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ute @ 2003-12-11 14:03 UTC (permalink / raw)


hello,

I'm trying to instantiate a generic package with doesn't become visible in
the
main program. However, the specifiacation of the package and the package
body do
separately compile without errors. I am using GNAT.

The specifiaction is as follows:

generic

--generisches Element: entweder float oder integer zur Laufzeit

type Elem is private;

with function ">"(X, Y: Elem) return boolean;

with procedure put(X: Elem);

with procedure get(X: Elem);

package generic_sort is

type ArrTyp is array (1..10) of Elem;



procedure swap (X, Y: in out Elem);

procedure sort(Arr: in out ArrTyp);

procedure put_array(Arr: in ArrTyp);

procedure get_array(Arr: out ArrTyp);

end generic_sort;



The main program, where it does not become visible:

with Ada.Text_IO; use Ada.Text_IO;

with Ada.Float_Text_IO; use Ada.Float_Text_IO;

with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

with generic_sort;



procedure generic_sort_demo is

package int_arrr_sort is new generic_sort(Integer, ">", put, get);

use int_arr_sort;

Arr: ArrTyp;

begin

put("Bitte geben Sie die Feldwerte ein!");

get_array(Arr);

new_line;

put("Das unsortierte Array: ");

put_array(Arr);

new_line;

sort(Arr);

put("Das sortierte Array: ");

put_array(Arr);

new_line;


end generic_sort_demo;




I can't find the error??

Thanx, ute





^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Problem with visibility of generic package help please
@ 2003-12-11 14:37 amado.alves
  0 siblings, 0 replies; 6+ messages in thread
From: amado.alves @ 2003-12-11 14:37 UTC (permalink / raw)
  To: comp.lang.ada

<<The main program, where it does not become visible:

with Ada.Text_IO; use Ada.Text_IO;

with Ada.Float_Text_IO; use Ada.Float_Text_IO;

with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

...>>

You're withing and using Ada.Integer_Text_IO two times!?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with visibility of generic package help please
  2003-12-11 14:03 Problem with visibility of generic package help please Ute
@ 2003-12-11 15:15 ` Georg Bauhaus
  2003-12-11 18:07 ` Jeffrey Carter
  2003-12-16 21:00 ` Martin Krischik
  2 siblings, 0 replies; 6+ messages in thread
From: Georg Bauhaus @ 2003-12-11 15:15 UTC (permalink / raw)


Ute <Ute.Usenet@web.de> wrote:
: hello,
: 
: I'm trying to instantiate a generic package with doesn't become visible in
: the
: main program. However, the specifiacation of the package and the package
: body do
: separately compile without errors. I am using GNAT.
: 
: 
: I can't find the error??

One reported error is,
generic_sort_demo.adb: no visible subprogram matches the specification for "put"
generic_sort_demo.adb: missing specification for "Width" and other formals

meaning that what you pass for put has a different specification
from what you have specified as generic formal procedure put in
generic_sort.ads.  Namely, your specifications do not list the
Width and other parameters that put from the text_IO packages have.


-- Georg



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with visibility of generic package help please
@ 2003-12-11 15:55 ada_wizard
  0 siblings, 0 replies; 6+ messages in thread
From: ada_wizard @ 2003-12-11 15:55 UTC (permalink / raw)
  To: comp.lang.ada

MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
User-Agent: Internet Messaging Program (IMP) 3.2.1

"Ute" <Ute.Usenet@web.de> writes:

> I'm trying to instantiate a generic package with doesn't become
> visible in the main program. However, the specifiacation of the
> package and the package body do separately compile without errors. I
> am using GNAT.

First, congratulations on learning Ada! it is a great language :)

When I tried to compile your program (with GNAT 3.15p), I got
many error messages. They are telling you what the problem is; you 
just need practice in reading them.

gnatmake -k -O3 -gnatn -gnatwa -I.. generic_sort_demo

Note that I have all warnings turned on (-gnatwa); this is very
helpful.

gcc -c -I./ -O3 -gnatn -gnatwa -I.. -I- ..\generic_sort_demo.adb
generic_sort_demo.adb:5:09: warning: no entities of "float_text_io" are referenced
generic_sort_demo.adb:7:09: warning: no entities of "integer_text_io" are referenced
generic_sort_demo.adb:9:09: warning: no entities of "integer_text_io" are referenced

These are hints that the "put" functions you want to use are not being
used.

generic_sort_demo.adb:17:60: no visible subprogram matches the specification for
"put"

In generic_sort.ads, you have a generic formal procedure parameter:

   with procedure put(X: Elem);

However, the actual declaration of Put in Ada.Integer_Text_IO is:

   procedure Put
     (Item  : in Num;
      Width : in Field := Default_Width;
      Base  : in Number_Base := Default_Base);

The Width and Base parameters have defaults, but that doesn't mean you
can leave them out in generic formals.

generic_sort_demo.adb:17:60: missing specification for "Width" and other formals
with defaults

Which is what this error message says :). GNAT has great error
messages, but you do have to get in the right mind set to read them.

So you need to add the missing parameters in the Put for generic_sort.

Note that Ada.Float_Text_IO has different parameters; you cannot
declare one generic formal procedure Put for both integer and float. 

generic_sort_demo.adb:17:65: no visible subprogram matches the specification for
"get"
generic_sort_demo.adb:17:65: missing specification for "Width"

Same as above.

generic_sort_demo.adb:19:08: "int_arr_sort" is undefined
generic_sort_demo.adb:19:08: possible misspelling of "int_arrr_sort"

This is clear, I hope; you typed 3 r's by mistake. GPS and Emacs will
automatically correct this sort of error, at a single keystroke.

generic_sort_demo.adb:21:09: "ArrTyp" is not visible
generic_sort_demo.adb:21:09: non-visible declaration at generic_sort.ads:15
generic_sort_demo.adb:27:04: "get_array" is not visible
generic_sort_demo.adb:27:04: non-visible declaration at generic_sort.ads:25
generic_sort_demo.adb:33:04: "put_array" is not visible (more references follow)
generic_sort_demo.adb:33:04: non-visible declaration at generic_sort.ads:23
generic_sort_demo.adb:37:04: "sort" is not visible
generic_sort_demo.adb:37:04: non-visible declaration at generic_sort.ads:21

These can be somewhat confusing. You are trying to use the subprograms
defined by your generic; the problem is that the generic instantiation
failed, so they are not visible. GNAT tries to be helpful and find
other places where the same names are visible. In this case, it
guessed wrong.


I suggest you separate the "put" functionality from the "sort"
functionality; put them in separate packages. That will help a lot.

You should consider using SAL.Gen_Array_Text_IO
(http://www.toadmail.com/~ada_wizard/) for the "put" part; it "just
works", and supports integer and float arrays "out of the box", so you
can just focus on the "sort" part. Even if this is homework, I would
not call it cheating; having to do complex Text_IO in order to do the
"real work" is just annoying. So take advantage of what's out there.

-- 
-- Stephe

___________________________________________________________
This mail sent using ToadMail -- Web based e-mail @ ToadNet



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with visibility of generic package help please
  2003-12-11 14:03 Problem with visibility of generic package help please Ute
  2003-12-11 15:15 ` Georg Bauhaus
@ 2003-12-11 18:07 ` Jeffrey Carter
  2003-12-16 21:00 ` Martin Krischik
  2 siblings, 0 replies; 6+ messages in thread
From: Jeffrey Carter @ 2003-12-11 18:07 UTC (permalink / raw)


Ute wrote:

> generic
> 
> --generisches Element: entweder float oder integer zur Laufzeit
> 
> type Elem is private;
> 
> with function ">"(X, Y: Elem) return boolean;
> 
> with procedure put(X: Elem);
> 
> with procedure get(X: Elem);

In addition to the other fine comments you've received, note that your 
generic formal procedure Get has its parameter of mode "in", which is 
probably not going to be very useful.

-- 
Jeff Carter
"Sir Lancelot saves Sir Gallahad from almost certain temptation."
Monty Python & the Holy Grail
69




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with visibility of generic package help please
  2003-12-11 14:03 Problem with visibility of generic package help please Ute
  2003-12-11 15:15 ` Georg Bauhaus
  2003-12-11 18:07 ` Jeffrey Carter
@ 2003-12-16 21:00 ` Martin Krischik
  2 siblings, 0 replies; 6+ messages in thread
From: Martin Krischik @ 2003-12-16 21:00 UTC (permalink / raw)


Ute wrote:

> hello,
> 
> 
> with Ada.Text_IO; use Ada.Text_IO;
> 
> with Ada.Float_Text_IO; use Ada.Float_Text_IO;
> 
> with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
> 
> with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
> 
> with generic_sort;

Hind for readability: don't "use" as much. it is better to rename:

package F_IO renames Ada.Float_Text_IO;
package I_IO renames Ada.Integer_Text_IO;
package IO renames Ada.Text_IO;

That way you can see where which comand comes from. Also you avoid name
clashes.

With Regards

Martin
 
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-12-16 21:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-11 14:03 Problem with visibility of generic package help please Ute
2003-12-11 15:15 ` Georg Bauhaus
2003-12-11 18:07 ` Jeffrey Carter
2003-12-16 21:00 ` Martin Krischik
  -- strict thread matches above, loose matches on Subject: below --
2003-12-11 14:37 amado.alves
2003-12-11 15:55 ada_wizard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox