Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site callan.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!harvard!talcott!panda!genrad!decvax!tektronix!hplabs!sdcrdcf!trwrb!scgvaxd!wlbr!callan!tim From: tim@callan.UUCP (Tim Smith) Newsgroups: net.lang.c Subject: Re: how has C bitten you? Message-ID: <1062@callan.UUCP> Date: Mon, 5-Aug-85 21:36:39 EDT Article-I.D.: callan.1062 Posted: Mon Aug 5 21:36:39 1985 Date-Received: Mon, 12-Aug-85 01:17:12 EDT References: <4051@alice.UUCP> <5400010@prism.UUCP> Organization: Callan Data Systems, Westlake Village, CA Lines: 29 > > Consider, for example, the following program fragment: > > > > 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? > The UniSoft System V C compiler for the 68k will reliably produce an infinite loop here. Note that i and a[] are both on the stack. This is what you get: ( high address higher up on page ) i: 4 bytes a[9]: 4 bytes . . . a[0] 4 bytes a[10] will overwrite i. -- Tim Smith ihnp4!{cithep,wlbr!callan}!tim 661