Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!prls!pyramid!hplabs!analog!kim From: kim@analog.UUCP (Kim Helliwell ) Newsgroups: net.micro.mac Subject: Re: Megamax bug? Message-ID: <219@analog.UUCP> Date: Wed, 11-Jun-86 11:44:00 EDT Article-I.D.: analog.219 Posted: Wed Jun 11 11:44:00 1986 Date-Received: Sat, 14-Jun-86 03:43:32 EDT References: <1023@k.cs.cmu.edu> Distribution: net Organization: Analog Design Tools, Menlo Park, CA. Lines: 26 > Keywords: > > > I'm working in Megamax C, and I noticed a problem while I was in the > debugger. It comes from these statements: > > for (i = ntables; i--; ) > if (i == -1) > > I would expect this to get the value of i, decrement the stored value, > and then exit or execute the statement. Rather, it tests the value > before it decrements, and the loop exits with i = 0. Is this a bug > in the code generation, or is C supposed to do this? > > Greg It's not a MegaMax bug, it's a Greg bug (:-). You have the i-- in the slot that is supposed to be the termination condition--so your description sounds like exactly what I would expect to happen. If you want the i-- to decrement i without testing it for equality to 0 first, it has to be after the second semicolon: for (i = ntables; ; i--) if (i = -1) Kim Helliwell