Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!mcvax!ukc!kcl-cs!glasgow!taylor From: taylor@glasgow.glasgow.UUCP (Jem Taylor) Newsgroups: net.lang Subject: Re: and if you put this in your language ... Message-ID: <447@glasgow.glasgow.UUCP> Date: Wed, 12-Mar-86 16:37:53 EST Article-I.D.: glasgow.447 Posted: Wed Mar 12 16:37:53 1986 Date-Received: Sat, 15-Mar-86 21:35:13 EST References: <1187@mmintl.UUCP> Reply-To: taylor@glasgow.UUCP (Jem Taylor) Organization: Comp Sci Dept, Glasgow Univ, Scotland Lines: 28 In article <1187@mmintl.UUCP> franka@mmintl.UUCP (Frank Adams) writes: >One often winds up writing this in the form: > if (A) then X; > if (A && B) then Y; else Z; >However, this fails if executing X changes the value of A (or if A has side >effects); and if evaluating A is expensive, the additional evaluation may be >undesirable. In languages where the order of execution is not specified for >the 'and' operator, the evaluation of (A && B) may fail if evaluation of B >is not valid unless A is true and/or X has been executed (which is fairly >common). > >In C, one often sees something like: > > if (A && (X, B)) then Y; else Z; > >However, this only works if X can be written in-line. > if (A) { X; if (B) Y; else Z; } else Z; If Z is so large that it is not reasonable to have two copies of it's code, it's time to make it a separate procedure anyway. -Jem.