Suppose I have the following code
IF (a.eq.0.or.M(a)) THEN
With a an integer and M(1:3) an array of logicals. If a is equal to 0, then I expect the first test to catch it and the second one never to be evaluated. However, if I use the intel fortran compiler and compiles with
-check all
then I got a segmentation fault. No error occurs without this debugging option. Is it a standard behavior? For many languages it is said explicitly in the manual that for
IF (A.or.B) THEN
if A is true then B is not evaluated. Does the Fortran standard explicitly requires that A and B can be evaluated even if does not impact the final result?
Fortran allows for, but does not guarantee, short-circuit evaluation of logical operators. So to be safe, you will have to write your code under the assumption that each operand is evaluated.