Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!mtune!codas!cpsc6a!rtech!jas From: jas@rtech.UUCP (Jim Shankland) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <980@rtech.UUCP> Date: Mon, 29-Jun-87 12:40:17 EDT Article-I.D.: rtech.980 Posted: Mon Jun 29 12:40:17 1987 Date-Received: Sat, 4-Jul-87 22:20:42 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <22250@sun.uucp> <17193@cca.CCA.COM> <6034@brl-smoke.ARPA> Reply-To: jas@rtech.UUCP (Jim Shankland) Organization: Relational Technology, Alameda CA Lines: 28 In article <6034@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In this silly debate, people have been making noises that sound as if >they thought !p and p!=NULL were equivalent. They of course have >opposite meaning, which perhaps helps make the point that one should >"say what one means" rather than trying to take clever shortcuts. Good point. Another example: I frequently see code written on a VAX that incorrectly says "if (*p)" instead of "if (p)" or "if (p != NULL)". Granted, inexperienced C programmers are more likely to make this mistake (then again, staying on the VAX, they never learn better); I still suggest that it is less error-prone to use NULL for zero-valued pointers, '\0' for the zero-valued character, and "if (e)" only if e is CONCEPTUALLY boolean (i.e., it is a variable declared as the typedef 'bool', or its main operator is a relop, or....). This is, indeed, a silly debate, and I'm sure we will never come to consensus; but years of moving other people's C code to dozens of different machines has absolutely convinced me that being able to say: if (integer-or-pointer-valued-expr) is an error-prone misfeature, and that we'd all be better off programming as though it didn't exist. -- Jim Shankland ..!ihnp4!cpsc6a!\ rtech!jas ..!ucbvax!mtxinu!/