Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!lll-lcc!unisoft!dual!ucbvax!jade!eris!mwm From: mwm@eris.BERKELEY.EDU (Mike (Don't have strength to leave) Meyer) Newsgroups: comp.lang.c Subject: Re: Not only that, but... Message-ID: <1638@jade.BERKELEY.EDU> Date: Tue, 11-Nov-86 16:04:56 EST Article-I.D.: jade.1638 Posted: Tue Nov 11 16:04:56 1986 Date-Received: Wed, 12-Nov-86 20:31:55 EST References: <166@houligan.UUCP> Sender: usenet@jade.BERKELEY.EDU Reply-To: mwm@eris.BERKELEY.EDU (Mike (Don't have strength to leave) Meyer) Organization: Missionaria Phonibalonica Lines: 26 In article <166@houligan.UUCP> dave@murphy.UUCP (H. Munster) writes: >In article <630@dg_rtp.UUCP>, throopw@dg_rtp.UUCP (Wayne Throop) types: >>Again folks, play it safe: *NEVER* have two side-effects on a single >>object in a single expression. > >Not only that, but: don't even *USE* an assigned-to object anywhere else >in the expression! The first isn't quite sufficient, as Dave showed. But the second is an over-reaction. There are operators in C that are guaranteed to preserve order, so you can make an assignment then use the variable assigned to. To wit, '||' and '&&' WILL be evaluated left-to-right (and short circuit), so you can safely write: while ((c = getchar()) != TERMINATOR && c != EOF) ; Since leaving off the test for EOF is usually a bug, this is a good thing. I know, this example can be rewritten as a do-while, and you can move subsequent tests to the top of the loop with breaks. But the first case isn't always true, and the second isn't as readable as the above C idiom.