TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show HTML Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Tucker Taft <[log in to unmask]>
Reply To:
Date:
Tue, 19 Oct 1999 22:06:29 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (39 lines)
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]

ATOM RSS1 RSS2