EOF considered harmful

David Goodenough dg at lakart.UUCP
Sat Oct 28 02:29:18 AEST 1989


ian at r6.UUCP (Ian Cottam) sez:
> 3) The, to my mind, awful idiom in 1) above is avoided, with the extra
>    benefit that the ``(ch= getchar() != EOF)'' slip up will not be made.

	while (EOF != (ch = getchar()))
	  putchar(ch);

NOW try leaving the parentheses off the (ch = getchar()) bit. As a side
note (and as has already been observed) the general construct:

	if (CONSTANT == variable)

will always be safer than:

	if (variable == CONSTANT)

because CONSTANT isn't an lvalue, so the compiler complains if you put
= instead of ==
-- 
	dg at lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp at xait.xerox.com			  +---+



More information about the Comp.lang.c mailing list