Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!ihuxy!steffen From: steffen@ihuxy.UUCP (Joe Steffen) Newsgroups: net.lang.c Subject: Re: What should be added to C ( really = in boolean context ) Message-ID: <1423@ihuxy.UUCP> Date: Wed, 4-Jun-86 12:11:24 EDT Article-I.D.: ihuxy.1423 Posted: Wed Jun 4 12:11:24 1986 Date-Received: Sat, 7-Jun-86 05:48:16 EDT References: <852@bentley.UUCP> <1514@mmintl.UUCP> <2881@utcsri.UUCP> Organization: AT&T Bell Laboratories Lines: 40 > >>Urgh. Are you talking about removing the assignment-has-a-value feature > >>completely, or a special case for "if (v = e)"? (I always write this as > >>"if ((v = e) != 0)" to make it clear that I didn't mean "if (v == e)".) > >> > > > Somebody mentioned that Lint could warn about using an assignment value > in a boolean context - unless you said /* BOOLEUSED */. I think the > warning is a good idea, but the new special comment is not. You can just > as easily write ( (v=e)!=0 ) and get same code on any non-silly compiler. > > I wouldn't mind a compiler warning if an assignment op were used in > *any* boolean context ( including being the operand of !, ||, && , and > the expr. before a ? ). Note that boolean context is inherited by the > RHS of a ',' and by e2 and e3 in e1?e2:e3. I added a simple check to buildtree() in the pcc compilers I support to warn of and = op directly under a CBRANCH op, which is used by if, while, and the middle expression in a for statement. This caught many latent bugs in our project's code, many which were of the form if (rc = f() != 0) The warning can be ignored on while (*p++ = *q++) or preferably changed to while ((*p++ = *q++) != 0) for clarity, as stated above. Unfortunately many pcc compiler generate a useless compare instruction for the latter, since the condition codes are already set by the move instruction on many machines. With another simple change to optim() in the compiler to remove the != 0 under a CBRANCH op, I solved this objection to adding the != 0, and the compiler generates less code! -- Joe Steffen, AT&T Bell Labs, Naperville, IL, (312) 979-5381