how has C bitten you?

Chris Torek chris at umcp-cs.UUCP
Sat Aug 3 05:35:07 AEST 1985


>> 	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 at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list