Fortran segmentation error if tests

Suppose I have the following code

IF (a.eq.0.or.M(a)) THEN 

With an integer and M (1: 3) an array of booleans. If a is 0, then I expect the first test to catch it, and the second will never be evaluated. However, if I use the Intel fortran compiler and compile with

  -check all 

then I got a segmentation error. No error occurs without this debugging option. Is this standard behavior? For many languages, the manual explicitly states that for

  IF (A.or.B) THEN 

if A is true, then B is not evaluated. Is the Fortran standard explicitly a requirement for evaluating A and B, even if it does not affect the end result?

+4
source share
1 answer

Fortran allows, but does not guarantee, a short evaluation scheme for logical operators . To be safe, you will have to write your code under the assumption that each operand is evaluated.

+13
source

Source: https://habr.com/ru/post/1400286/


All Articles