[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]

Re: &* in C, you win!



> + If sizeof(int)==sizeof(char), testing EOF can indeed be a problem
> if if happens to be a valid data value, in which case feof() will
> have to be used to tell the two cases apart.

WHAT??!!

>From K&R Volume 1, section 2.7 (type conversions), discussing why
Status: RO

getchar() returns an int:

  The real reason for using int instead of char is not related to any
  questions of possible sign extension.  It is simply that getchar must
  return all possible characters (so that it can be used to read arbitrary
  input) and, in addition, a distinct EOF value.  Thus its value _cannot_
  be represented as a char, but must instead be stored as an int.

I realize that ANSI occasionally comes up with strange stuff, but breaking

	int c;
	...
	while ((c = getchar()) != EOF) {
		...
	}

is beyond the pale.

What's this for?  "Nice" int compilers for 8-bit machines?  2-byte int
compilers for machines with BIG character sets?

	michael