Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ccieng6.UUCP Path: utzoo!watmath!clyde!burl!ulysses!harpo!seismo!rochester!ritcv!ccieng5!ccieng6!dwr From: dwr@ccieng6.UUCP ( Donald Wallace Rouse II) Newsgroups: net.lang.c Subject: Re: C programming style poll Message-ID: <160@ccieng6.UUCP> Date: Tue, 1-May-84 19:01:35 EDT Article-I.D.: ccieng6.160 Posted: Tue May 1 19:01:35 1984 Date-Received: Wed, 2-May-84 06:31:20 EDT References: <2735@azure.UUCP> Organization: Computer Consoles Inc., Rochester, NY Lines: 43 xxxxxxxxxxxxxxxxxxxxxxxx > > (1) y = (x == 5); > > > (2) y = 0; > if (x == 5) > y = 1; > > 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) According to the K&R bible, p. 41 at the top: Another useful form of type conversion is that relational expressions like i > j and logical expressions connected by && and || are defined to have value 1 if true, and 0 if false. Thus the assignment isdigit = c >= '0' && c <= '9'; sets isdigit to 1 if c is a digit and to 0 if not. Therefore, it IS legal (though bad form, in my opinion) to use the form "(y == 1)" or "(y != 1)". I use this definition occasionally to access arrays, as in: char * tf [] = {"false", "true"}; ... printf ("The supposition that x is 0 is %s\n", tf [x == 0]); D2