Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!lll-crg!nike!cad!ucbvax!decvax!tektronix!uw-beaver!uw-june!entropy!dataio!bright From: bright@dataioDataio.UUCP (Walter Bright) Newsgroups: net.lang.c Subject: Re: What should be added to C : if (a=b) Message-ID: <1008@dataioDataio.UUCP> Date: Thu, 29-May-86 13:09:42 EDT Article-I.D.: dataioDa.1008 Posted: Thu May 29 13:09:42 1986 Date-Received: Tue, 3-Jun-86 20:54:15 EDT Reply-To: bright@dataio.UUCP (Walter Bright Organization: Data I/O Corp., Redmond WA Lines: 27 In article <446@cad.BERKELEY.EDU> keppel@pavepaws.UUCP (David Keppel) writes: > How about an option to lint(1) (this doesn't help the people who > don't have lint) that looks for conditional clauses with assignment > but no test. Thus > if ( (a = expr) == value ) { ... > would pass cleanly thru lint, while > if ( a = expr ) { ... > would generate a message indicating a potential problem. Datalight C generates a warning for this: if ( a = expr) { ^ Warning: possible unintended assignment. In fact, it will also generate the same warning for stuff like: !(a = expr) (e1 == e2 && e3 = e4) etc. > There could be a "lint comment" /* BOOLTESTED */ or some such: > if ( a = expr ) { /* BOOLTESTED */ > that would also serve as documentation to say to another reader of > the code "Yes, I really meant '=' and not '=='". The BOOLTESTED is unnecessary. Simply write: if ((a = expr) != 0) { which will not trigger the warning.