🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.micro.mac
Article #6014

Re: Megamax bug?

#6014
From: Kim Helliwell
Date: Wed, 11 Jun 1986 15:44
26 lines
1426 bytes
> 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--; ) <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

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--) <statement>
	if (i = -1) <more statements>

Kim Helliwell
Technical Details
Message-ID: <219@analog.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!linus!philabs!prls!pyramid!hplabs!analog!kim
References: <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!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