Re: potential runtime problem on arm, powerpc and s390 due to incorrect assumption on char signedness
Previously Gerhard Tonn wrote:
> >>The following code fragment will ignore the end-of-file when char is
> >>implemented using unsigned char, due to internal conversions between data
> >> char c;
> >> while ((c = getchar()) != EOF)
> >> process character in c
> In other contexts the right solution is to make the type of the variable
> 'signed char'.
No, the right solution here is make c of type `int'. getchar() does
not return a char for a very obvious reason: if it did one would not
be able to distinguish between a valid character read from the keyboard
and an error condition.
/firstname.lastname@example.org This space intentionally left occupied \
| email@example.com http://www.liacs.nl/~wichert/ |
| 1024D/2FA3BC2D 576E 100B 518D 2F16 36B0 2805 3CB8 9250 2FA3 BC2D |