comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Global scope for instantiated generic package?
Date: Mon, 30 Aug 2010 06:30:17 -0700 (PDT)
Date: 2010-08-30T06:30:17-07:00	[thread overview]
Message-ID: <c5d472f0-6d9c-46fb-a79a-7fac82e4eab9@a36g2000yqc.googlegroups.com> (raw)
In-Reply-To: 5vWdnTd5Lf6uM-bRnZ2dnUVZ_oidnZ2d@giganews.com

Trogdor wrote on comp.lang.ada:
> I wish to manipulate very large integers with values in the
> trillions.  This would require a 64 bit integer type, so to maintain
> portability I specify a new type using range and let the compiler do
> the right thing.
>
> type BigInt is range 1..10_000_000_000_000;
>
> I then wish to get and put these values, so I instantiate
> Integer_IO.
>
> package BigInt_IO is new integer_IO(BigInt);
>
> My program consists of three parts: the main body, a package spec
> and a package body (the package containing all the subprograms and
> functions).
>
> 1) Is this the way to do it, or is there a preffered way?
>
> 2) Where, speciffically, do I place the above two lines (and the
> associated "with" line) so that I can BigInt_io.get from the main
> body and the package subprograms as well?
>
> So far, every place I have tried has offended the compiler.  And my
> text books have been of little help (I have more on order).
>
> Thanks for the help!

Without at least a sekeleton of your sources I'm not sure I understand
your question, so for clarity I'll assume you currently have:

with Ada.Text_IO;
package P is
   type BigInt is range 1..10_000_000_000_000;
   package BigInt_IO is new Ada.Text_IO.Integer_IO (BigInt);

   procedure Proc (X : out BigInt);
end P;

package body P is
   procedure Proc (X : out BigInt) is
   begin
      BigInt_IO.Get (X); -- OK
   end Proc;
end P;

with P;
procedure Main is
   X : BigInt;
begin
   P.Proc (X); -- OK
   BigInt_IO.Get (X); -- error, BigInt_IO not directly visible
   P.BigInt_IO.Get (X); -- OK
end Main;

You can resolve the error in two ways:
1) add a "use P;" clause in procedure Main
2) Declare BigInt_IO at library level, like so:

-- bigint_io.ads
with Ada.Text_IO;
with P;
package BigInt_IO is new Ada.Text_IO.Integer_IO (P.BigInt);

and then add "with BigInt_IO" clauses in both the body of P and the
body of Main.

HTH

--
Ludovic Brenta.



  parent reply	other threads:[~2010-08-30 13:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-30 13:12 Global scope for instantiated generic package? Trogdor
2010-08-30 13:25 ` Jacob Sparre Andersen
2010-08-30 13:28 ` Georg Bauhaus
2010-08-30 13:30 ` Ludovic Brenta [this message]
2010-08-30 13:47 ` Dmitry A. Kazakov
2010-08-30 18:49 ` Jeffrey Carter
replies disabled

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