Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.c Subject: Re: how has C bitten you? Message-ID: <1082@umcp-cs.UUCP> Date: Fri, 2-Aug-85 15:35:07 EDT Article-I.D.: umcp-cs.1082 Posted: Fri Aug 2 15:35:07 1985 Date-Received: Sat, 3-Aug-85 21:15:04 EDT References: <4051@alice.UUCP> <5400010@prism.UUCP> Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 29 >> int i, a[10]; >> for (i = 0; i <= 10; i++) >> a[i] = 0; >> >> On many implementations, this will result in an infinite loop. >This looks to me like it will simply overwrite one int's worth of >memory beyond the end of the array "a" with the value 0. Granted, >depending on what happens to be after "a", this can have disastrous >results, but is there really an implementation in which it will >(reliably) lead to infinte looping? How does "every PCC implementation" grab you? (Actually, I suspect there may three or four PCC implementations in which it won't run forever, but it *will* run forever on 4BSD Vaxen.) >On the other hand, in an implementation where char's are unsigned, >this common construct WILL lead to an unterminating loop. > > char x; > while (--x) I assume you mean "while (--x >= 0)". I only use this on "register int"s (especially since it generates a sobgeq if the loop's small enough). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland