Date:
Tue, 19 Oct 1999 22:06:29 -0400
MIME-Version:
1.0
Content-Transfer-Encoding:
7bit
Content-Type:
text/plain; charset=us-ascii; x-mac-type="54455854";
x-mac-creator="4D4F5353"
|
Jeff Creem wrote:
> > > My code looks much clearer if I use expressions like 2**4 instead of 16,
> > > but
> > > then there is the question of execution time also. I don't want the
> > > calculation to take place over and over again, since the function is
> > > called
> > > quite often.
> > >
> > [Borgia:]
> >
> > You may want to try declaring the 2**4 expression as a constant,
> > which guarantees a static value at compile time regardless of the
> > implementation or level of optimization. I hate code that relies on a
> > particular optimizer anyway.
> >
>
> In this case I agree with you but in general I disagree with the
> general feeling that you hate code that relies on a particular
> optimizer.
This particular case has nothing to do with optimization. All validated
Ada compilers are required to evaluate "static" expressions at compile-time.
2**4 is static, as are essentially all operations involving numeric literals,
named numbers, or named constants whose initial value is static. See section
4.9 (or so) of the manual.
...
> Jeff Creem
>
> (P.S - For all of the versions of Rational compilers I have used (VADS and
> Apex, 68000, MIPS PowerPC and
> Solaris). Each of them would have optimized that code to a constant.
This is not an optimization, but rather a language requirement.
-Tucker Taft [log in to unmask]
|
|
|