Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!husc6!linus!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <840@mcgill-vision.UUCP> Date: Mon, 13-Jul-87 01:14:58 EDT Article-I.D.: mcgill-v.840 Posted: Mon Jul 13 01:14:58 1987 Date-Received: Tue, 21-Jul-87 03:49:31 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <1597@sfsup.UUCP> Organization: McGill University, Montreal Lines: 27 In article <1597@sfsup.UUCP>, mpl@sfsup.UUCP writes: > In article <13112@topaz.rutgers.edu>, ron@topaz.rutgers.edu.UUCP writes: >> To do this right you need an extra int temporary value >> while ((i = getchar()) != EOF) >> followed by c = i; > Since when? WHat's wrong with: > int c; > while ((c = getchar()) != EOF) { > /* use c as you would any char variable */ > /* because char's are promoted to int ANYWAY */ > /* in expressions - no need for a temp variable */ > } The difference becomes significant if you ever take the address of c. For example, write(fd,&c,1); takes on an entirely different meaning. If c is a char, this is portable (provided sizeof(char)==1 -- are there any machines on which this is not true?), but if c is an int you get what you probably expect on a little-endian and it breaks mysteriously on a big-endian. der Mouse (mouse@mcgill-vision.uucp)