Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c Subject: Re: What should be added to C ( really = in boolean context ) Message-ID: <2881@utcsri.UUCP> Date: Sun, 1-Jun-86 11:58:15 EDT Article-I.D.: utcsri.2881 Posted: Sun Jun 1 11:58:15 1986 Date-Received: Sun, 1-Jun-86 12:23:22 EDT References: <852@bentley.UUCP> <1514@mmintl.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 37 Summary: not just if(..)... In article <1514@mmintl.UUCP> franka@mmintl.UUCP (Frank Adams) writes: >In article <852@bentley.UUCP> kwh@bentley.UUCP writes: >>>>o There should be an option to flag statements of the form if (v = e) ... >>>>(Actually, I wouldn't be averse to a coding standard which forbade such >>>>things, in favor of if (v = e, v) ...) >> >>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)".) >> > >Actually, I was not proposing removing the assignment-has-a-value feature >anywhere (although I would not put it into a new language I was designing). >The proposal was that it be avoided in if's (and probably while's as well) >as a coding standard. That is, it would be legal, but not recommended. > 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. ( Note I did not say "good optimizing compiler", which are widely believed to be capable of witchcraft :-) ). ( v=e, v ) would probably get you the same code, too - ditto ( v=e, v!=0). The comma-less version may be a mite faster in some cases. The presence of a 0 encourages the programmer to be explicit as to what kind of zero is being used: while( p=p->link, p != NULL ){ ... 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. -- "We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg