Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner

Code failure only in XE2015 and not earlier versions

HI,

REAL X(2)

N = 2

DO I=1,N+1

if( i .LE. N .and. MOD(X(i),10).EQ.2) A= A+B

ENDDO

The above code has worked fine in all past versions. But now using XE2015 it throws an exception when I=3 as it thinks the bounds of X are violated.  But it shouldn't need to evaluate the second test as the first will fail.  Is there a switch we need to set now for this to not fail?  Or do we have to rewrite all the instances of this code to be 2 IF tests?

Thanks,

Dave

0 Kudos
3 Replies
Highlighted
Valued Contributor II

if( i .LE. N) if( MOD(X(i),10

if( i .LE. N) if( MOD(X(i),10).EQ.2) A= A+B

Fortran doesn't have short-circuiting logical operators.

 

0 Kudos
Highlighted
Black Belt

R.O. has given you a concise

R.O. has given you a concise answer. In Fortran, expressions can be evaluated in any order, subject to rules regarding parentheses, etc. Therefore, your code should not be written such a way that it depends on a particular order in order to work correctly.

Observe that you are giving mixed arguments (one real, the other integer) to MOD. This should be corrected.

Your code might work (and might even work as expected) if you did not specify bounds checking, but it is not good to tolerate such unstable code. 

0 Kudos
Highlighted
Beginner

ah the trouble with not

ah the trouble with not posting the real code, where X is actually an integer...

0 Kudos