Checksum: 39837 Lines: 19 Path: utzoo!lsuc!sq!msb From: msb@sq.uucp (Mark Brader) Date: Sun, 6-Mar-88 18:54:19 EST Message-ID: <1988Mar6.185419.25314@sq.uucp> Newsgroups: comp.lang.c Subject: Re: Signedness of chars References: <23209@ucbvax.BERKELEY.EDU> <7413@brl-smoke.ARPA> Reply-To: msb@sq.UUCP (Mark Brader) Organization: SoftQuad Inc., Toronto > > ... That is, how many programs would break if > > `unsigned char' and `char' were the same type? Doug Gwyn notes: > The most common portability error in this regard is > char c; > while ((c = getchar()) != EOF) > ... [c should of course be int] In fact, this is a bug in any case, if the code is supposed to handle binary data. On machines where chars are signed, this loop will wrongly terminate as soon as it reads a byte containing the value (char)EOF, i.e. usually 0xFF. I have encountered programs that failed in precisely this way. Mark Brader "When a supposedly indivisible transaction SoftQuad Inc., Toronto fails to complete properly, this is known utzoo!sq!msb, msb@sq.com as an atomic bomb." -- Peter Neumann