how has C bitten you?
Tim Smith
tim at callan.UUCP
Tue Aug 6 11:36:39 AEST 1985
> > 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
More information about the Comp.lang.c
mailing list