Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!homxb!mhuxt!mhuxm!mhuxo!ulysses!sfmag!sfsup!mpl From: mpl@sfsup.UUCP Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <1728@sfsup.UUCP> Date: Fri, 31-Jul-87 17:09:48 EDT Article-I.D.: sfsup.1728 Posted: Fri Jul 31 17:09:48 1987 Date-Received: Sun, 2-Aug-87 10:27:16 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <24246@sun.uucp> Organization: AT&T-IS, Summit N.J. USA Lines: 59 Summary: portability In article <24246@sun.uucp>, guy%gorodish@Sun.COM (Guy Harris) writes: > > Oddly enough, by definition what you have used above is a valid > > construct on just about every machine I have ever seen. > > "valid", yes, in the sense that the C compiler won't reject it; it may > give you a warning, but it won't reject it. [deleted stuff] > main() > { > int c = 'a'; > > write(1, &c, 1); > } So, the point is (if I remember the original article correctly) that one should use: main() { int i; char c; while ((i = getchar()) != EOF) { c = i; write(1, &c, 1); } } perhaps. However, why not use the (more efficient) code: main() { int i; while ((i = getchar()) != EOF) putchar(i); } I mean, I think this all stemmed from an early reply to the original article which claimed you *needed* an intermediate variable (i) no matter *what* you wanted to do with the character. For code like this "write" business an intermediate (c) might be useful, but you can still do without in a better fashion. How about: #include main() { int i; while ((i = getchar()) != EOF) write(1, lobyte(loword(i)), 1); } ANSI C promises to be better at providing standard macros like this as well. So.... Happy hacking! Mike