From owner-freebsd-hackers Wed Mar 6 2:38: 2 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from critter.freebsd.dk (critter.freebsd.dk [212.242.86.163]) by hub.freebsd.org (Postfix) with ESMTP id 6E83337B416; Wed, 6 Mar 2002 02:37:58 -0800 (PST) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.12.2/8.12.2) with ESMTP id g26AbgLv030204; Wed, 6 Mar 2002 11:37:42 +0100 (CET) (envelope-from phk@critter.freebsd.dk) To: "Mike Meyer" Cc: obrien@FreeBSD.ORG, Mike Meyer , Giorgos Keramidas , hackers@FreeBSD.ORG Subject: Re: RFC: style(9) isn't explicit about booleans for testing. In-Reply-To: Your message of "Wed, 06 Mar 2002 04:30:32 CST." <15493.61384.557931.883967@guru.mired.org> Date: Wed, 06 Mar 2002 11:37:42 +0100 Message-ID: <30203.1015411062@critter.freebsd.dk> From: Poul-Henning Kamp Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message <15493.61384.557931.883967@guru.mired.org>, "Mike Meyer" writes: >I'll grant that the change Paul suggested makes it clear - the >programmer knows when the function is returning an int or not. But >it's not clear that it achieves his intent. is > > char *p; > if (p = somerandomfunction(with, args)) { > } > >really less readable than: > > char *p; > if ((p = somerandomfunction(with, args)) != NULL) { > } Ahh, but here you hit one of my pet-peeves. I hate assignments inside conditionals. I prefer the above written as: char *p; p = somerandomfunction(with, args); if (p != NULL) { } Anyway, if you want it spelled out the way I would want it: 0. No assignments in if() 1. In conditions, pointers should be explicitly compared against NULL: if (foo == NULL) or if (foo != NULL) 2. In conditions, non-interger numeric types should be explicitly compared to zero if (float_t == 0.0) 3. Integers need not be explicitly compared to zero: if (foo & MASK) not if ((foo & MASK) != 0) -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message