Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!tmsoft!mason From: mason@tmsoft.UUCP Newsgroups: comp.lang.c Subject: Re: short circuit evaluation & side-effects Message-ID: <107@tmsoft.UUCP> Date: Wed, 4-Feb-87 11:23:48 EST Article-I.D.: tmsoft.107 Posted: Wed Feb 4 11:23:48 1987 Date-Received: Wed, 4-Feb-87 20:39:51 EST References: <425@bobkat.UUCP> <102600001@datacube> <7610@utzoo.UUCP> Reply-To: mason@tmsoft.UUCP (Dave Mason) Organization: TM Software Associates, Toronto Lines: 23 Summary: Does ANSI change the statement re: side effects? In K&R pg. 184 it says: "...Otherwise the order of evaluations of expressions is undefined. In particular the compiler considers itself free to compute subexpressions in the order it believes most efficient, even if the subexpressions involve side effects. The order in which side effects take place is undefined." As I understand it this means the results of: (1) x = *i++ * (1 - *i++); is unpredicatable. ANSI added the unary + to fix this (as well as for numerical analysis (i.e. floating point) calculations) so that: (2) x = +(*i++ * (1 - *i++)); does what one would expect. I have seen notes here that suggested that (1) could be equivalent to: (3) x = *i * (1 - *i); i += 2; Does the unary + force the side effects to happen where expected? Is unary + still in the ANSI standard proposal? The above quote would appear to require side effects to take place (although the order is undefined) even if short circuiting were to be done (except of course in the case of || and &&) -- ../Dave Mason, TM Software Associates (Compilers & System Consulting) ..!{utzoo!ryesone seismo!mnetor utcsri!ryesone}!tmsoft!mason