CBFalconer said:
However it is far from trivial to convert an unsigned char into
EOF.
That's impossible and makes no sense too.
The issue here is whether it makes sense to pass EOF to fputc or putc.
As they take an int expression for their first arguments, it is
possible to do so. That value is then converted inside [f]putc to an
unsigned char value and written to the stream specified. Then this byte
is cast to int and returned, if there are no write errors, in which
case EOF is returned.
I think the issue is whether both of these two (simplified)
implementations of fputc are correct, as per the Standard:
int fputc(int ch, FILE *s) {
if (write((unsigned char)ch, s) == SUCCESS) return (unsigned char)ch;
else { s->err_flag = 1; return EOF; }
}
int fputc(int ch, FILE *s) {
if (write((unsigned char)ch, s) == SUCCESS) return ch;
else { s->err_flag = 1; return EOF; }
}
I think that the Standard doesn't allow the second implementation. The
relevant part is 7.19.7.3 of n1256.