Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Code failure only in XE2015 and not earlier versions

dajum
Novice
327 Views

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
JVanB
Valued Contributor II
327 Views

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

Fortran doesn't have short-circuiting logical operators.

 

0 Kudos
mecej4
Honored Contributor III
327 Views

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
dajum
Novice
327 Views

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

0 Kudos
Reply