Array indexing vs. pointers...

Dan Schlitt dan at ccnysci.UUCP
Sat Oct 22 00:13:25 AEST 1988


In article <8630 at smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <1700 at dataio.Data-IO.COM> bright at dataio.Data-IO.COM (Walter Bright) writes:
>>Here's some of the things I do:
>
>I have to take exception to most of these micro-efficiency tweaks.
>Most of them have no effect on the code generated by even a moderately
>good compiler, and nearly all of them make the code more obscure.
>It is much more important for the source code to be patently correct
>than for every surplus nanosecond to be squeezed out.  Fast, buggy
>code does nobody a service, and bugs are hard to spot when the source
>code is obscure.  Besides, most efficiency losses are from poor
>choice of data structures or algorithms, not from fatty source code.

	[Much deleted]
Doug clears up much misguided stuff.

>
>>    o	Use temporaries to eliminate all common subexpressions.
>
>That can actually interfere with a good optimizer.  Use
>temporaries when you suspect that many optimizers will not
>take care of the common subexpression for you; otherwise
>if it is not in a bottleneck section of code, leave it alone.

The first language I coded in was SOAPII and I soon moved on to early
versions of fortran.  Compilers in those days were dumb and hand
optimization in the source code and the assembler output were the 
thing of the day.  This was undoubtedly encouraged by youthful visions of
infalibility.  Also nobody thought seriously about hauling their
programs off to some other kind of computer.

Compilers are much better now.  Age has encouraged a modesty which
allows that the compiler may well know how to do things better than I
do.  That is certainly the case when I take my code off to some
unfamiliar computer.

I have concluded, and I think this is what Doug is saying, that one
should not code in a way that will confuse either the reader of the
code or the compiler.

If your compiler doesn't do a good job of optimization then your money
probably is spent better on a better compiler than it is on the time
of coders diddling with the code.

But that is just the opinion of some old codger and probably should be
ignored.

-- 
Dan Schlitt                        Manager, Science Division Computer Facility
dan at ccnysci                        City College of New York
dan at ccnysci.bitnet                 New York, NY 10031
                                   (212)690-6868



More information about the Comp.lang.c mailing list