comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: 'Digit in generic package
Date: 1996/08/27
Date: 1996-08-27T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.96Aug27134451@spectre.mitre.org> (raw)
In-Reply-To: 9608261530.AA06035@most


In article <9608261530.AA06035@most> "W. Wesley Groleau (Wes)" <wwgrol@PSESERV3.FW.HAC.COM> writes:

  > At least one vendor supplied a generic math package that did exactly
  > that AND on examining the disassembled code for an instantiation, we
  > found that the compiler had looked at the parameters and eliminated
  > the "dead code" so that the effect was exactly what Mr. O'Keefe had
  > asked for.

   This is what you should expect in some--but not all--cases.

  > Now I wonder whether in Ada 95 it would work to simplify R. Eachus's
  > suggestion with

  >   ...
  >   function Generic_F ... is

  >	 Precision : constant := Max(Foo'Digits,Bar'Digits,...);

  >    begin
  >      case Precision is ...

    Make that:

      Precision : constant := Integer'Max(Foo'Digits,Bar'Digits);

   ...and the compiler should accept it if, and only if, all (sub)type
names are static.  This requires both static bounds, an that the type
not be a generic formal parameter.  (The initialization expression for
Precision must be static both in the generic and the instance.) If you
say instead:

      Precision: constant Integer := Integer'Max(Foo'Digits,Bar'Digits);

   then Precision can be static in the instance even though it is not
static in the generic template.  This is exactly the behavior
commented on above.  And if an instance is such that some code can be
statically eliminated, most compilers will do so.  (There is at least
one compiler on the market which uses a generic model which prevents
this, but that is an accepted trade-off.  By not doing any generic
instantiations at compile time, the resulting code size is smaller.)


					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  reply	other threads:[~1996-08-27  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-26  0:00 'Digit in generic package W. Wesley Groleau (Wes)
1996-08-27  0:00 ` Robert I. Eachus [this message]
1996-08-28  0:00   ` Robert Dewar
1996-08-27  0:00 ` Ken Garlington
replies disabled

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