down

Guy Harris guy at auspex.UUCP
Wed Dec 14 10:55:06 AEST 1988


>Doesn't the expression (c = getchar()) have type (int) regardless of the
>type of c?  Or will c being a char really prevent this comparison?

>From K&R Second Edition (based on some particular d of the dpANS); K&R
First edition says much the same thing:

	A7.17 Assignment Expressions

	   ...The type of an assignment expression is that of its left
	operand, and the value is the value stored in the left operand
	after the assignment has taken place.

So no, the expression has the same type as "c", which is type "char",
not "int", and it has the value that was stored in "c".  If "getchar()"
returned EOF, and EOF is -1 (as it is on most, if not all, UNIX
implementations of C) on an 8-bit-byte two's complement machine the
value '\377' is stored in "c".  When the comparision with EOF is done,
the "char" value of the expression is converted to "int"; if "char"s are
unsigned, the '\377' is converted to 255, which is definitely not equal
to -1 (EOF).... 



More information about the Comp.lang.c mailing list