how has C bitten you?
Peter DaSilva
peter at kitty.UUCP
Fri Aug 2 00:18:39 AEST 1985
> I am collecting examples of how C can bite the unwary user.
>
> 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.
I assume you mean that auto's are allocated on the stack so &a[10]==&i.
I don't see an easy solution to this, except for built-in range checking.
I think "Safe/C" has this...
Anyone who uses "<=" in a for(;;) loop to initialise an array should be
strung up by their index(3) fingers and forced to listen to Sonny Bono
chanting "Zero Origin Arrays" until their ears fall off [:->].
More information about the Comp.lang.c
mailing list