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

FOR LOGIC

dondilworth
New Contributor II
733 Views
My code has lines like this:

IF (JBLN .GT. 1 .AND. JRF .EQ. JRFN(JBLN-1)) GO TO 4

If JBLN equals 1, then the first test fails and there is no need to do the second test. But the compiler does it anyway, and since (JBLN-1) equals 0, the program crashes since the array starts at 1. CVF did this correctly and did not crash.

Is that a compiler error, a defect in Intel Fortran, or is there a setting somewhere that makes it do the logical thing?
0 Kudos
1 Solution
Paul_Curtis
Valued Contributor I
733 Views
This issue has been brought up here, probably dozens of times. Fortran will always correctly evaluate the overall argument, but the compiler never promises to evaluate compound expressions in "left to right" as written, or any other order. So what you need to do is separate the logic explicitly:

IF (jbln > 1) THEN
IF (jrf == jrfn(jbln-1)) GOTO 4
END IF

which will always prevent a null-index situation.

View solution in original post

0 Kudos
2 Replies
Paul_Curtis
Valued Contributor I
734 Views
This issue has been brought up here, probably dozens of times. Fortran will always correctly evaluate the overall argument, but the compiler never promises to evaluate compound expressions in "left to right" as written, or any other order. So what you need to do is separate the logic explicitly:

IF (jbln > 1) THEN
IF (jrf == jrfn(jbln-1)) GOTO 4
END IF

which will always prevent a null-index situation.
0 Kudos
Steven_L_Intel1
Employee
733 Views
0 Kudos
Reply