Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-spam!mordor!lll-tis!ames!oliveb!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <22635@sun.uucp> Date: Thu, 2-Jul-87 21:11:36 EDT Article-I.D.: sun.22635 Posted: Thu Jul 2 21:11:36 1987 Date-Received: Sat, 4-Jul-87 10:12:54 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <13112@topaz.rutgers.edu> Sender: news@sun.uucp Lines: 16 > The assignment into a character causes getchar's int return > to be changed to char, invalidating the following comparison The > effect is that characters of value 0xFF will cause erroneous end of > file indication. This is a common error in C, but it is fortunate > that most text this is used on never contains any characters with the > most significant bit set. On a machine where "char" is not signed, this won't work even if you run it on text consisting entirely of 7-bit characters. "getchar" will return EOF when it hits end-of-file; EOF (-1) will get converted to '\377' (we assume 8-bit characters here; translate as needed for other character sizes) which compares equal to 255 but not to -1. Thus, you'll never see the end-of-file indication. Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com