Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!burl!codas!killer!jfh From: jfh@killer.UUCP Newsgroups: comp.unix.questions,comp.lang.c Subject: Re: Wierd Compilers Message-ID: <1988@killer.UUCP> Date: Wed, 4-Nov-87 12:17:47 EST Article-I.D.: killer.1988 Posted: Wed Nov 4 12:17:47 1987 Date-Received: Sat, 7-Nov-87 17:24:03 EST References: <367@white.gcm> <18964@amdcad.AMD.COM> <44177@beno.seismo.CSS.GOV> Organization: Big "D" Home for Wayward Hackers Lines: 50 Keywords: Sun Xref: utgpu comp.unix.questions:4269 comp.lang.c:5021 Summary: But there is a difference. In article <44177@beno.seismo.CSS.GOV>, rick@seismo.CSS.GOV (Rick Adams) writes: > Even a mediocre compiler should be able to recognize that > a++; > is equivalent to > ++a; > if there is no assignment, etc. > > There is really no excuse for not making this trivial optimization. You should > not have to depend on the user doing it. > > --rick I really hadn't expected Rick to come up with that one. Guess working for the government was gone to his brain ... (Sorry, couldn't pass up a anti-government dig ;-). I have recapped the story for the comp.lang.c folks. The code in question was while (a--) vs. while (--a) ; ; which is the same as while (a-- != 0) vs. while (--a != 0) ; ; the pre-decrement loop makes one less trip since the value of `a' is decremented _prior_ to the test (not actually though). Consider the case where a == 1. The --a will equal 0 and the test will fail. In the case of a--, the value _prior_ to the decrement is used and the test will pass, so the loop gets executed. To be the same, assuming `a' is not used in the loop, you would have to code a++; while (--a) ; to get the same number of trips (assuming overflow was not a problem). This would be a big win if the code in the loop was very small and the value of `a' was large. I wouldn't do it since the time savings would be small, and the code a kluge. Of course, documentation helps. - John. -- John F. Haugh II HECI Exploration Co. Inc. UUCP: ...!ihnp4!killer!jfh 11910 Greenville Ave, Suite 600 "Don't Have an Oil Well?" Dallas, TX. 75243 " ... Then Buy One!" (214) 231-0993