Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!security!genrad!mit-eddie!mit-vax!eagle!mhuxl!ihnp4!inuxc!pur-ee!uiucdcs!parsec!ctvax!uokvax!andree From: andree@uokvax.UUCP Newsgroups: net.lang Subject: Re: Superstition in Programmers - (nf) Message-ID: <5016@uiucdcs.UUCP> Date: Fri, 20-Jan-84 23:08:02 EST Article-I.D.: uiucdcs.5016 Posted: Fri Jan 20 23:08:02 1984 Date-Received: Sun, 22-Jan-84 04:28:40 EST Lines: 33 #R:abnjh:-34800:uokvax:9000020:000:1555 uokvax!andree Jan 19 19:02:00 1984 /***** uokvax:net.lang / bbncca!keesan / 4:45 pm Jan 10, 1984 */ ---------------------------- Actually, I don't consider "counting downwards to 0 instead of upwards to how_many_times" to be superstitious behaviour, as Mark Brader does. I do this myself, but I do it on purpose and with the knowledge of why I do it, which is that on many (most?) machines, a comparison with zero is cheaper than comparison with other constants -- that is, the machine instruction takes fewer bytes ior is faster. Likewise, I will use comparisons like "i < 0" in favor of "i == -1" when possible (e.g. checking for error returns from U*IX system calls) because I know that checking sign is smaller/faster than comparison to constant. -- Morris M. Keesan {decvax,linus,wjh12}!bbncca!keesan keesan @ BBN-UNIX.ARPA /* ---------- */ Ahh, yes, the good old "trying to outsmart the compiler" kludge. Are you sure that what you are doing is faster for ALL compilers, and ALL machines? Take a look at Kernighan & Plaugher's "Elements of Programming Style" (I THINK thats where it's at) for an example of that kind of thing. Turns out that on the compilers they tested, it either didn't make any difference, or made the code run SLOWER! This kind of thing belongs in the compiler. I don't know what PCC does for any specific machine, but at least one z80 C compiler maps x == -1 into (x + 1) == 0, as the comparison is faster. I think the result is even faster than the code generated for x < 0. "Let the compiler do the simple optimizations"