Infinite loops

Joseph S. D. Yao jsdy at hadron.UUCP
Sun May 4 00:54:10 AEST 1986


In article <117 at brl-smoke.ARPA> gwyn at BRL.ARPA (VLD/VMB) writes:
>do ... while(1);
>while(1) ...
>for(;;) ...
>are all widely-used idioms for unconditional looping in C.
>I personally prefer the latter, but the choice is just a
>matter of taste.  Any reasonable compiler will generate
>efficient code for all three constructs.

Unfortunately, as I'm sure many readers of this group will agree,
not all compilers are reasonable.  The only one that consistently
doesn't generate useless code is for (;;) {...}.

BTW, given all these defines:  here are some "cute" ones of mine:

#define ever	(;;)	/* for ever ...; */
#define unless(x)	if (!(x))	/* unless (x) ...; */
#define until(x)	while (!(x))	/* until (x) ...;
					   do ... until (x); */

and of course	[ given #define OK 0 ]

#define streq(a,b)	(strcmp(a, b) == OK)
#define strneq(a,b,n)	(strncmp(a, b, n) == OK)
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.lang.c mailing list