Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 (Tek) 9/26/83; site azure.UUCP Path: utzoo!watmath!clyde!burl!ulysses!harpo!seismo!hao!hplabs!tektronix!teklds!azure!philipl From: philipl@azure.UUCP (Philip Lantz) Newsgroups: net.lang.c Subject: Re: C programming style poll Message-ID: <2735@azure.UUCP> Date: Fri, 27-Apr-84 07:04:41 EDT Article-I.D.: azure.2735 Posted: Fri Apr 27 07:04:41 1984 Date-Received: Mon, 30-Apr-84 05:37:41 EDT Organization: Tektronix, Beaverton OR Lines: 36 From a style point of view, I personally prefer y = (x == 5); WITH the parentheses, but NOT without them. I think Boolean expressions are as valid a part of the C language as they are of Pascal, even though there is no specific declaration for Boolean variables. However, since I have a compulsion to write the tightest code possible, I use y = 0; if (x == 5) y = 1; What's that? Yes, on every C compiler I've checked (pcc and Ritchie and others) the version with the "if" generates BETTER code than either of the other two forms. (The other two forms generate identical code.) By the way, I agree that the first form above may not be guaranteed to be entirely equivalent to the others, but if y is assigned to a Boolean expression, it should be tested with if (y) if (!y) or possibly if (y == 0) if (y != 0) but never with if (y == 1) if (y != 1) The first four forms generate better code (no compare instruction on most machines), but especially do not depend on the value of a Boolean being 1 when true. Philip Lantz Tektronix, Inc. tektronix!tekmdp!philipl