On Thu, Jun 14, 2018 at 1:14 PM, Janus Weil <ja...@gcc.gnu.org> wrote:
> > > Am 14. Juni 2018 11:41:03 MESZ schrieb Janne Blomqvist < > blomqvist.ja...@gmail.com>: > >On Thu, Jun 14, 2018 at 11:38 AM, Janus Weil <jaydu...@gmail.com> > >wrote: > > > >> > >> Am 14. Juni 2018 10:05:24 MESZ schrieb Janne Blomqvist < > >> blomqvist.ja...@gmail.com>: > >> > >> >Either > >> > > >> >a) short-circuiting in left-to-right order > >> > > >> >or > >> > > >> >b) must evaluate all the arguments in left-to-right order > >> > > >> >My preference would be for a) as that is what most languages are > >doing, > >> > >> Well, C/C++ has two different kinds of operators that give you the > >choice > >> to specify whether you want short-circuiting or not. > > > >Presumably you're thinking of "&" and "|". But to be pedantic, those > >are > >bitwise operators, not non-short-circuiting boolean operators > > Yes, but they work perfectly fine as logical operators on booleans, don't > they? > > > >There are however situations where > >they are not equivalent to hypothetical non-short-circuiting boolean > >operators! > > Could you give a simple example of such a case? > With the usual representation of integers, for A=1, B=2, both A and B by themselves will evaluate as true, A&&B will evaluate to true, but A&B will evaluate to false. >>but > >> >even b) would be better than leaving it undefined. > >> > >> Agreed. > >> > >> In my opinion the best strategy for gfortran in the current situation > >> would be to apply short-circuiting whenever it can be proven that it > >has no > >> observable consequences. E.g. a function call should not be optimized > >away > >> unless it is pure. > > > >Hmm, why? I don't see why always evaluating everything is less wrong > >than > >short-circuiting? > > I'm not saying it is "less wrong", but it can be less efficient. In that > sense my proposed strategy is a compromise that tries to avoid harmful > optimizations but still does optimization where it is safe. > If the user assumes short-circuiting, then evaluating everything is surprising. If the user assumes everything will be evaluated, short-circuiting is surprising. So whatever is done, somebody will think we're doing it wrong. So in lieu of the standards committee getting their act together on this issue, I suggest we do whatever is most efficient, and generate a warning. -- Janne Blomqvist