From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,db5c6b2ef47d4b9e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-21 10:24:29 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!news-reader.ntrnet.net!uunet!ash.uu.net!xyzzy!nntp From: Jeffrey Carter Subject: Re: short-circuit control forms X-Nntp-Posting-Host: e246420.msc.az.boeing.com Content-Type: text/plain; charset=us-ascii Message-ID: <3B322970.5475A25E@boeing.com> Sender: nntp@news.boeing.com (Boeing NNTP News Access) Content-Transfer-Encoding: 7bit Organization: The Boeing Company X-Accept-Language: en References: <3B312495.15258B18@boeing.com> <1YbY6.213292$p33.4311302@news1.sttls1.wa.home.com> Mime-Version: 1.0 Date: Thu, 21 Jun 2001 17:05:52 GMT X-Mailer: Mozilla 4.5 [en]C-CCK-MCD Boeing Kit (WinNT; U) Xref: archiver1.google.com comp.lang.ada:8991 Date: 2001-06-21T17:05:52+00:00 List-Id: Mark Lundquist wrote: > > "Jeffrey Carter" wrote in message > news:3B312495.15258B18@boeing.com... > > > > IANAL, nor do I play one on TV. However, "and" and "or" are normal > > subprograms (you can overload them), and the semantics for subprograms > > state that all actual parameters are evaluated, and the order of > > evaluation is not specified by the language (ARM 6.4). Thus, it is > > illegal for a compiler to convert them to short-circuit forms. > > I don't think that's correct... > > The compiler can do whatever it wants, as long as it's equivalent [RM > 1.1.3]. Since preserving side effects is part of "equivalent", and deciding if functions have side effects is "hard" (I'm not aware of any compilers that do this), this is true in theory but irrelevant in practice. If a function with a side effect is (part of) an operand of "and" or "or", a compiler must generate code that calls the function. In real compilers, that seems to mean that both operands are always evaluated. Is anyone aware of a compiler that optimizes away evaluation of an operand to "and" or "or" when neither operand has a function call? In cases where one of the operands has a function call? Both operands? As I said, IANAL. It would be nice to hear from Robert Duff, Tucker Taft, or Robert Dewar about this. -- Jeffrey Carter