comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Can the main procedure be a generic instance?
Date: Sat, 9 Nov 2002 14:39:42 -0600
Date: 2002-11-09T14:39:42-06:00	[thread overview]
Message-ID: <mailman.1036874462.18225.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: EZbz9.59081$sP2.19438@sccrnsc02

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
> 
> 




      parent reply	other threads:[~2002-11-09 20:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]
replies disabled

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