From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 8 Apr 93 22:35:25 GMT From: munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!usenet@uunet.uu.net (Andrew Dunstan,,2285592,) Subject: Re: and then Message-ID: <1q29bd$7d8@huon.itd.adelaide.edu.au> List-Id: >>From article <1993Apr7.162133.3564@nosc.mil>, by sampson@nosc.mil (Charles H. Sampson): [ should we always use short-circuit boolean forms?] > > My style is to use the boolean operators generally, reserving the > short-circuit forms to document that the second operand should not be eval- > uated under some circumstances. > Your style is correct. Your reservations (see below) are not. Still, it's better to do the right thing for the wrong reason than the other way around :-) > Unfortunately, that style can conflict with efficiency considerations. > Ada compiler writers appear to have abdicated their responsibility and make > no attempt to determine when boolean operations can be optimized as short- > circuit. (Somebody contradict me, please.) They apparently feel that if ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ OK. > the programmer wants short-circuit he can ask for it. In addition, there > are cases when it is unreasonable to expect such an optimization; when the > second operand contains a function reference, for example. > The LRM (4.5.5) says: the operands of an expression that does not contain a short-circuit control form are evaluated in some order that is not defined by the language (but before application of the corresponding operator). So, the compiler writers are correct in not attempting to cast non-short circuit forms to short-circuit evaluation. There could well be cases where evaluation of both operands is wanted (if evaluation of one or both has a desired side-effect). If so, "optimising" evaluation of one away is highly undesirable. Leaving the order undefined also ALLOWS the compiler writer the chance to optimise the order of evaluation. In summary, if you want short-circuit, ask for it. If not, let the compiler do the evaluation of both operands the best way it can. # Andrew Dunstan # There's nothing good or bad # # net: # # # adunstan@steptoe.adl.csa.oz.au # but thinking makes it so. # # or: andrewd@cs.adelaide.edu.au # # # Andrew Dunstan # There's nothing good or bad # # net: # # # adunstan@steptoe.adl.csa.oz.au # but thinking makes it so. # # or: andrewd@cs.adelaide.edu.au # #