segmentation fault created by fortran if tests

2020-02-06 07:55发布

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?

1条回答
够拽才男人
2楼-- · 2020-02-06 08:52

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.

查看更多
登录 后发表回答