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

Need help with if statement

pecan204
Beginner
678 Views
Hello,
I have a if statement that is throwing an error with intel fortran.
This had previously worked with compaq fortran.
The statement is:
i=1
If ( i .gt. 1 .and. (.not.DF(i)) .and. DF(i-1))
The compiler states an error on DF subscript is 0 error which is less than lower bound apparently for 3rd statement, but I thought it would be stopped by 1st statement when i = 1.
Any comments?
Thanks
0 Kudos
4 Replies
Steven_L_Intel1
Employee
678 Views
Fortran doesn't work that way - there is no requirement of left-to right evaluation of logical operands nor of "short circuiting". The compiler is allowed to evaluate "any logically equivalent expression" it cares to.

Use nested IF-THEN to protect the second expression.
0 Kudos
pecan204
Beginner
678 Views
Steve,
This did work fine in CVF.
Was there a change when it became Intel?
Also is there a list of differences that might help convert to intel from CVF?
Thanks
Ken
0 Kudos
pecan204
Beginner
678 Views
Here is another one.
do while( i .le. 80 .and. (.not.DF(i)))
It throws an array out of bounds error on the DF when i=81.
I guess I'll split that one up also.
Do logicals get if check before integers?
Thanks
0 Kudos
Steven_L_Intel1
Employee
678 Views
If it "worked", it was by accident, not design. It's entirely up to the compiler's optimization as to what gets evaluated when. With CVF, we had plenty of complaints where it didn't work the way you thought it would.
This is not a change - you are relying on undefined behavior.
0 Kudos
Reply