Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 (Denver Mods 4/2/84) 6/24/83; site drutx.UUCP Path: utzoo!watmath!clyde!burl!mgnetp!ihnp4!drutx!opus From: opus@drutx.UUCP (ShanklandJA) Newsgroups: net.unix-wizards Subject: Re: getc() != EOF Message-ID: <407@drutx.UUCP> Date: Wed, 30-May-84 13:03:26 EDT Article-I.D.: drutx.407 Posted: Wed May 30 13:03:26 1984 Date-Received: Fri, 1-Jun-84 22:21:54 EDT References: <30@utastro.UUCP> <307@basser.SUN> Organization: AT&T Information Systems Laboratories, Denver Lines: 28 (sigh.) > > > while ( (c = getc()) != EOF ) > > > > > >ought to work. If somebody is to be blamed, it is surely not the > > >people who wrote the code, but the people who made a C implementation > > >that broke it. > > > > It will work if "c" is declared "int." > > It will not work if "c" is declared "char." > > > > WRONG! The code above will work if c is int or char. > Char variables are promoted to int in expressions (see C manual) > and a char -1 is IDENTICAL with an int -1. Unsigned char c could be > different (Any C implementors there? (kvm?)). > > Chris Maltby > University of Sydney But it is not defined whether char is a signed of unsigned type in C. On machines where char is unsigned, c will never have the value -1, and the comparison with EOF will always fail. All this is quite clearly described on page 40 of K&R. Jim Shankland ..!ihnp4!druxy!opus