bgoldma@geinah.UUCP (04/24/87)
I have found a bug in f77 released with 4.3. When a comparison of a
substring delimited by nonevaluated expressions is anded with another
the results are not always correct. Here is a sample program illustrating
this. The problem is because "(1)" is evaluated differently than "1".
By the same token, using a variable such as "j" will work, but using
"j+1" will not. It has something to do with when it is evaluated and
compiling with the optimizer usually fixes this by cheating. I do not
have a fix for this and I do not know exactly what the error is.
program bug
character*2 atom
logical row
atom(1:1) = 'H'
atom(2:2) = 'H'
if(atom((1):(1)).eq.'H') print*,'first true'
if (atom((2):(2)).eq.'H') print*,'second true'
C HERE IS THE BUG
row = ((atom((1):(1)).eq.'H').and.(atom((2):(2)).eq.'H'))
print*,'first and second is ',row
C The problem the f77 has is evaluating an integer expression used
C as substring delimiters when in a boolean and the boolean is
C only temporary. This is not the case if the integer is a constant
C as can be seen by the example below.
C HERE IS THE BUG
C HERE IS THE CORRECT OUTPUT
row = ((atom(1:1).eq.'H').and.(atom(2:2).eq.'H'))
print*,'first and second is ',row
C HERE IS THE CORRECT OUTPUT
end
BILL Goldman