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

Re: potential runtime problem on arm, powerpc and s390 due to incorrect assumption on char signedness



On Sun, Jan 13, 2002 at 08:46:44PM +0100, Wichert Akkerman wrote:
> 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
> > >>types:
> > >>
> > >>                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.

Well, the original post said:
"and the EOF is ignored.  The correction is to make the type of
variable c int."

I guess that's why it says "in OTHER contexts".

-- 
Peter Mathiasson                   | GPG Fingerprint:
E-Mail: peter(at)mathiasson(dot)nu |  A9A7 F8F6 9821 F415 B066
Web   : http://www.mathiasson.nu   |  77F1 7FF5 C2E6 7BF2 F228

The adress used in the From: header is valid until 2002/02/13.
Please send messages to my real adress listed above.

Attachment: pgpfKANkEZduq.pgp
Description: PGP signature


Reply to: