TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Proportional Font
Show Text 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:
Jeff Creem <[log in to unmask]>
Reply To:
Jeff Creem <[log in to unmask]>
Date:
Tue, 19 Oct 1999 22:37:37 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (56 lines)
Stuff deleted.

> > >         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.
> > >
> >

My response :
> > 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.
>

Tucker Tafts info

> 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.
>

Point taken. The point I was going after in my response was not one of
optimization but rather style.
The fact that the compiler will replace 20 occurrences of 2**4 with a static
expression
is nice (and I am glad to hear it is a requirement) but in any case for
style reasons I would
typically still want to see it done from a single constant unless there was
no better name
for the constant than Two_To_The_Fourth_Power which is one of the more
annoying
style of constant declarations I have seen.

But the discussion and answer info here from Tucker points out why writing
your code to
not require some particular compiler optimization is often silly since mere
mortals who were
not involved in writing the LRM are often assume they have to do something
to make the
code fast when in reality the compiler was required to do it for them.
Sometimes a hand rolled
optimization is the correct choice but not nearly as often as most
developers think.




Jeff

ATOM RSS1 RSS2