From: johnherro@aol.com (John Herro)
Subject: Re: Generic Packages
Date: 1996/03/22
Date: 1996-03-22T00:00:00+00:00 [thread overview]
Message-ID: <4iugrr$r4h@newsbf02.news.aol.com> (raw)
In-Reply-To: 4inq3c$lr9@NNTP.MsState.Edu
vkire@ERC.MsState.Edu (Kiril Nikola Vidimce) writes:
> ... I was wondering was if I could define a generic
> package with a generic constant/value that would
> be passed when instantiating the package.
Inside a generic package, generic formal parameters are treated as
constants in any case. The following example, which works in Ada 83 and
Ada 95, instantiates a generic package with a constant:
generic
Number : Integer;
package P is
procedure Show;
end P;
with Text_IO;
package body P is
procedure Show is
begin
Text_IO.Put_Line(Integer'Image(Number));
end Show;
end P;
with P;
procedure Test is
I : constant Integer := 3;
package P3 is new P(Number => I);
begin
P3.Show;
end Test;
As expected, the program displays 3, and if you attempt to add the
line
Number := Number + 1;
to procedure Show in the body of P, the compiler will reject the statement
as an assignment to a read-only object. However, that's still true even
if you remove the word constant from the line
I : constant Integer := 3;
in procedure Test. The generic formal parameter is treated as a constant
in any case.
For this reason you can't declare
generic
Number : constant Integer;
package P is ...
> I am very new in Ada ...
You've come to the right place! I hope this helps. Good luck
learning and using Ada; you'll like it!
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor
next parent reply other threads:[~1996-03-22 0:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4inq3c$lr9@NNTP.MsState.Edu>
1996-03-22 0:00 ` John Herro [this message]
1996-03-22 0:00 ` Generic Packages Samuel Tardieu
[not found] <5e03nm$esq@netty.york.ac.uk>
1997-02-15 0:00 ` Jon S Anthony
1997-02-20 0:00 ` phtruong
1997-02-21 0:00 ` Robert Dewar
1997-02-25 0:00 ` Quorlia
1997-02-27 0:00 ` Robert Dewar
1998-08-10 0:00 Tory Patnoe
1998-08-11 0:00 ` Robert I. Eachus
1998-08-11 0:00 ` Tucker Taft
1998-08-12 0:00 ` Dale Stanbrough
1998-08-17 0:00 ` Dr. Hubert B. Keller
1998-08-27 0:00 ` Simon Wright
-- strict thread matches above, loose matches on Subject: below --
2000-02-16 0:00 Generic packages David Olsson
2000-02-16 0:00 ` R. Tim Coslet
2001-04-19 21:27 Generic Packages Eyal Ben-gal
2001-04-19 20:26 ` Ehud Lamm
2001-04-19 22:09 ` Robert A Duff
2001-04-20 6:50 ` Ehud Lamm
2002-07-09 13:03 generic packages Sami Evangelista
2002-07-09 13:28 ` Fabien Garcia
2002-07-09 13:41 ` Sami Evangelista
2002-07-10 2:00 ` SteveD
2002-07-11 13:41 ` Sami Evangelista
2002-07-11 20:56 ` Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox