Article View: net.micro.mac
Article #6173Re: Megamax bug?
From: Jason Haines
Date: Tue, 17 Jun 1986 07:17
Date: Tue, 17 Jun 1986 07:17
30 lines
1484 bytes
1484 bytes
>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--; ) <statement>
> if (i == -1) <more statements>
>
>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
NEVER confuse the For statement - for(pre-int,test,re-init) <statement block>
Try the following:
for (i = ntables;;i--) <statement>
if (i == -1) < more statements>
/* Jason Haines ACSnet: baron@runx
* 73 Davidson Avenue CSNET: baron@runx.oz
* Concord NSW 2137 ARPA: baron%runx.oz@seismo.css.gov
* AUSTRALIA
*
* UUCP:
* {enea,hplabs,mcvax,prlb2,seismo,ubc-vision,ukc}!munnari!runx.oz!baron
*/
Technical Details
Message-ID:
<1250@runx.OZ>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!princeton!caip!lll-crg!seismo!munnari!moncskermit!basser!metro!ipso!runx!baronReferences:
<1023@k.cs.cmu.edu>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!princeton!caip!lll-crg!seismo!munnari!moncskermit!basser!metro!ipso!runx!baron From: baron@runx.OZ (Jason Haines) Newsgroups: net.micro.mac Subject: Re: Megamax bug? Message-ID: <1250@runx.OZ> Date: Tue, 17-Jun-86 03:17:17 EDT Article-I.D.: runx.1250 Posted: Tue Jun 17 03:17:17 1986 Date-Received: Wed, 25-Jun-86 04:55:20 EDT References: <1023@k.cs.cmu.edu> Organization: RUNX Un*x Timeshare. Sydney, Australia. Lines: 29