Mon, 18 Oct 1999 14:10:44 -0400
> > 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.
> 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. I have seen enough code that was written "hand Optimized" that
was probably slower and certainly less clear than the straightforward
code one typically produce.
For instance, at least under Ada 83 there was nothing that said that
a compiler had to pass an in parameter as a pointer even if it was large.
Also, I would not recommend falling back to address arithmatic just because
you get worried that the compiler does not support strength reduction
But again, in this case, seems like the constant might be a better design
(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.