bug or not in fortran compiler under linux 64 bits ?

bug or not in fortran compiler under linux 64 bits ?

the two forms below don't give the same result :

464 !              do m = 1,3
465 !                if (l2 == d(ntemp,m)) l = m
466 !                exit
467 !              end do

468             if (l2 == d(ntemp,1)) l = 1             
469             if (l2 == d(ntemp,2)) l = 2
470             if (l2 == d(ntemp,3)) l = 3
in the first case I get l = 2 and 3 (correct answer) in the second. (naturly the "!" character is switched as needed !)

What is wrong ? (compiler 2013.3.163)


4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Because of the EXIT statement in the DO loop, the loop is executed only once, with m = 1. If the comparison yields .FALSE., after the loop is exited the variable I will retain whatever value it had before the loop was entered.

Perhaps you mean to write, instead:

if (l2 == d(ntemp,m)) then

        l = m



In addition to exit issue previously discussed.

What are the values of l, l2 and d(ntemp,1:3) prior to entering code section given?

As the code is written, it is unknown to the reader as to if any of the if tests result in .true.
IOW l passes through the filter unchanged.

Jim Dempsey

>>Indeed the exit has to be included in the if branch

Doing so would not produce equivalent results (e.g. when all three in line if tests result in .true.)

Jim Dempsey

Leave a Comment

Please sign in to add a comment. Not a member? Join today