The C17 (N2176) standard states, "The fputc function returns the character written" (7.21.7.3) if there is no write error.
But in the context of
int c ;
// ... later, c is assigned an "interesting" value ...
int k = fputc ( c , stdout ) ;
is
k == c || k == EOF
always true
? I.e., provided that fputc
does not return EOF
, is it guaranteed to return c
? Put a third way, can fputc
write a character other than one equal to its first argument?
For example If I request output of the dollar sign (not guaranteed to be in the source or execution character sets, AFAICT), could '\u0024' != fputc('\u0024', stdout)
. Maybe the program will output a local currency symbol, instead.
Clarification
The question is
In C, when may
fputc
return other than its first argument?
Partial answers so far (2021-10-20) seem to be:
- when a write error occurs during
fputc
, - when
(unsigned char) c != c
I am still wondering
Suppose (unsigned char) c == c
, but (unsigned char) c
does not match a character in the execution character set. Is fputc
permitted to write some other character instead?
For example, suppose c == (unsigned char) '\u0024'
(ASCII dollar sign) does not exist in the execution character set (because execution character set is non-ASCII). Can fputc
write, say, another currency symbol instead (or some arbitrary character).