comp.lang.ada
 help / color / mirror / Atom feed
* Can the main procedure be a generic instance?
@ 2002-11-09 17:54 SteveD
  2002-11-09 19:10 ` sk
  2002-11-09 20:39 ` David C. Hoos, Sr.
  0 siblings, 2 replies; 4+ messages in thread
From: SteveD @ 2002-11-09 17:54 UTC (permalink / raw)


I have defined a generic package gen_main as follows:

---------- File: gen_main.ads ----------
with ada.Text_io;
package Gen_Main is

generic
    number_of_times : integer;
procedure Gen;

end Gen_Main;
----------------------------------------

---------- File: gen_main.adb ----------
with ada.Text_io;

package body Gen_Main is

procedure Gen is
begin
    for count in 1 .. Number_of_times loop
        Ada.Text_Io.Put_Line( "Count = " & Integer'Image( count ) );
    end loop;
end Gen;

end Gen_Main;
----------------------------------------

I create an instance of the generic

---------- File: main.adb ----------
with gen_main;
procedure main is new gen_Main.Gen( 10 );
-----------------------------------

This program builds and runs under ObjectAda 7.2 as expected.
Using Gnat 3.14p, I get the error:

D:\>gnatmake -v Main

GNATMAKE 3.14p  (20010503) Copyright 1995-2001 Free Software Foundation,
Inc.
  "main.ali" being checked ...
  -> "main.ali" missing.
gcc -c main.adb
main.adb:2:11: warning: file name does not match unit name, should be
"main.ads"

main.adb:2:11: generic instantiation for "main" does not allow a body
main.adb:2:11: remove incorrect body in file "main.adb"
End of compilation
gnatmake: "main.adb" compilation error


Should this work?

SteveD






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

* Re: Can the main procedure be a generic instance?
  2002-11-09 17:54 Can the main procedure be a generic instance? SteveD
@ 2002-11-09 19:10 ` sk
  2002-11-09 20:17   ` SteveD
  2002-11-09 20:39 ` David C. Hoos, Sr.
  1 sibling, 1 reply; 4+ messages in thread
From: sk @ 2002-11-09 19:10 UTC (permalink / raw)


Hi,

> ---------- File: main.adb ----------
> with gen_main;
> procedure main is new gen_Main.Gen( 10 );
> -----------------------------------

should be "main.ads". I beleive that this is
a vendor issue and not an Ada issue.

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

* Re: Can the main procedure be a generic instance?
  2002-11-09 19:10 ` sk
@ 2002-11-09 20:17   ` SteveD
  0 siblings, 0 replies; 4+ messages in thread
From: SteveD @ 2002-11-09 20:17 UTC (permalink / raw)


"sk" <noname@myob.com> wrote in message
news:mailman.1036869302.15503.comp.lang.ada@ada.eu.org...
> Hi,
>
> > ---------- File: main.adb ----------
> > with gen_main;
> > procedure main is new gen_Main.Gen( 10 );
> > -----------------------------------
>
> should be "main.ads". I beleive that this is
> a vendor issue and not an Ada issue.
>

Renaming the file to main.ads did the trick.  Thanks.

SteveD

> --
> -------------------------------------
> -- Merge vertically for real address
> -------------------------------------
> s n p @ t . o
>  k i e k c c m
> -------------------------------------





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

* Re: Can the main procedure be a generic instance?
  2002-11-09 17:54 Can the main procedure be a generic instance? SteveD
  2002-11-09 19:10 ` sk
@ 2002-11-09 20:39 ` David C. Hoos, Sr.
  1 sibling, 0 replies; 4+ messages in thread
From: David C. Hoos, Sr. @ 2002-11-09 20:39 UTC (permalink / raw)


The answer to your question is "yes."

There is no need to wrap a lone procedure in a package.
Just declare a generic library procedure and instantiate
it like this:
-- gen_main.ads --
with Ada.Text_IO;
generic
   Number_Of_Times : Integer;
procedure Gen_Main;
-- gen_main.adb --
with Ada.Text_IO;
procedure Gen_Main is
begin
   for Count in 1 .. Number_Of_Times loop
      Ada.Text_IO.Put_Line ("Count = " & Integer'Image (Count));
   end loop;
end Gen_Main;
-- main.ads --
with gen_main;
procedure main is new gen_Main (10);

Since the instantiation is a procedure specification, GNAT
requires the .ads extension if following its default
file naming rules.

----- Original Message ----- 
From: "SteveD" <nospam_steved94@attbi.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: November 09, 2002 11:54 AM
Subject: Can the main procedure be a generic instance?


> I have defined a generic package gen_main as follows:
> 
> ---------- File: gen_main.ads ----------
> with ada.Text_io;
> package Gen_Main is
> 
> generic
>     number_of_times : integer;
> procedure Gen;
> 
> end Gen_Main;
> ----------------------------------------
> 
> ---------- File: gen_main.adb ----------
> with ada.Text_io;
> 
> package body Gen_Main is
> 
> procedure Gen is
> begin
>     for count in 1 .. Number_of_times loop
>         Ada.Text_Io.Put_Line( "Count = " & Integer'Image( count ) );
>     end loop;
> end Gen;
> 
> end Gen_Main;
> ----------------------------------------
> 
> I create an instance of the generic
> 
> ---------- File: main.adb ----------
> with gen_main;
> procedure main is new gen_Main.Gen( 10 );
> -----------------------------------
> 
> This program builds and runs under ObjectAda 7.2 as expected.
> Using Gnat 3.14p, I get the error:
> 
> D:\>gnatmake -v Main
> 
> GNATMAKE 3.14p  (20010503) Copyright 1995-2001 Free Software Foundation,
> Inc.
>   "main.ali" being checked ...
>   -> "main.ali" missing.
> gcc -c main.adb
> main.adb:2:11: warning: file name does not match unit name, should be
> "main.ads"
> 
> main.adb:2:11: generic instantiation for "main" does not allow a body
> main.adb:2:11: remove incorrect body in file "main.adb"
> End of compilation
> gnatmake: "main.adb" compilation error
> 
> 
> Should this work?
> 
> SteveD
> 
> 
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 




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

end of thread, other threads:[~2002-11-09 20:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-09 17:54 Can the main procedure be a generic instance? SteveD
2002-11-09 19:10 ` sk
2002-11-09 20:17   ` SteveD
2002-11-09 20:39 ` David C. Hoos, Sr.

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