more questions about efficient C code (really lint)

Chris Torek chris at umcp-cs.UUCP
Tue Jul 2 11:53:40 AEST 1985


There is actually a difference between

	char c;

	while ((c = getchar()) != '\n')

and

	while (getchar() != '\n')

The latter expression compares the return value of getchar() (an
int) with '\n' (another int).  The former compares the value of
the assignment "c = getchar()" (a char) with an int.  Lint is
arguably correct in complaining, as "c" itself is not actually used
in the comparison, but it does have an effect.

By the way, the former section of code is technically incorrect:
getchar returns an int, since EOF is supposed to be something that
is not valid as a char.
-- 
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