Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!nrl-cmf!cmcl2!rocky8!cucard!ccnysci!dan From: dan@ccnysci.UUCP (Dan Schlitt) Newsgroups: comp.lang.c Subject: Re: Array indexing vs. pointers... Message-ID: <939@ccnysci.UUCP> Date: 21 Oct 88 14:13:25 GMT References: <836@proxftl.UUCP> <3105@hubcap.UUCP> <1700@dataio.Data-IO.COM> <8630@smoke.ARPA> Reply-To: dan@ccnysci.UUCP (Dan Schlitt) Organization: City College of New York Lines: 52 In article <8630@smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <1700@dataio.Data-IO.COM> bright@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@ccnysci City College of New York dan@ccnysci.bitnet New York, NY 10031 (212)690-6868