- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
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?
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
IF (jbln > 1) THEN
IF (jrf == jrfn(jbln-1)) GOTO 4
END IF
which will always prevent a null-index situation.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
IF (jbln > 1) THEN
IF (jrf == jrfn(jbln-1)) GOTO 4
END IF
which will always prevent a null-index situation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page