Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

segmentation fault created by fortran if tests

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?

like image 254
Mathieu Dutour Sikiric Avatar asked Mar 07 '12 21:03

Mathieu Dutour Sikiric


1 Answers

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.

like image 141
Ken Wayne VanderLinde Avatar answered Sep 20 '22 22:09

Ken Wayne VanderLinde