Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!apple!snorkelwacker.mit.edu!ai-lab!life!burley From: burley@albert.gnu.ai.mit.edu (Craig Burley) Newsgroups: comp.lang.fortran Subject: Re: Questions about IF Message-ID: Date: 24 Jun 91 02:00:51 GMT References: Sender: news@ai.mit.edu Organization: Free Software Foundation 545 Tech Square Cambridge, MA 02139 Lines: 43 In-reply-to: br0w+@andrew.cmu.edu's message of 23 Jun 91 16:55:59 GMT In article br0w+@andrew.cmu.edu (Bruno W. Repetto) writes: Suppose there is this IF command: IF(.AND..AND. ... .AND.)statement 1) Are the expressions evaluated from "left to right"? The standard doesn't mandate any particular order, even if the expressions have side effects -- if there are order dependencies in the side effects, then the program (probably) is not standard-conforming. 2) Supposing 1) above is true, if expressions 1 to i evaluate to .TRUE., and expression i+1 evaluates to .FALSE., are the subsequent expressions evaluated (if any remain), or is the execution of the IF command concluded right then? (First of all, 1) above is NOT true, but the answer might explain things further.) Again, it's entirely up to the compiler. A program that depends on expressions i+2 through the rest being evaluated even if i+1 evaluates .FALSE. is not standard-conforming -- for that matter, so is a program that depends on any of the expressions 1 through i being evaluated if i+1 evaluates .FALSE. (i.e. they evaluate to .TRUE.). In other words, if the compiler can somehow "divine" that testing expression i+1 first is a good idea (i.e. it has no side effects and is fairly simple), it can do it and skip the rest, so in IF (LFUNC1(X).AND.LFUNC2(Y).AND..FALSE.) STOP a standard-conforming compiler may make the entire statement effectively disappear even though LFUNC1 and LFUNC2 might perform important side effects; if they do (including modifying their arguments), the program is (potentially) not standard-conforming. The upshot of all this is that a great deal of flexibility is extended to the Fortran compiler writer by the standard, at the "expense" of the Fortran programmer, as compared to, say, the C language. This is one of the many reasons for preferring Fortran over C or vice versa, depending on the task at hand. -- James Craig Burley, Software Craftsperson burley@gnu.ai.mit.edu