- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if( i .LE. N) if( MOD(X(i),10).EQ.2) A= A+B
Fortran doesn't have short-circuiting logical operators.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ah the trouble with not posting the real code, where X is actually an integer...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page