Hi -
We are currently moving some code from Compaq 6 to Intel 10 and I am having difficulty with a particular item of code in a subroutine provided by a supplier.
My issue concerns multiple conditions in 'do while' or 'if' type statements. The code in question follows.
i = len( b )
do while( i.ge.1 .and. b(i:i).eq.' ' )
i = i - 1
enddo
Let's assume that b = ' ', a four character string in which all characters are blank spaces. In the code above, 'i' will eventually become 0 (which is the desired result), and then the last time that the 'do while' evaluates the conditions, it will see i.ge.1 (0.ge.1 = FALSE) and b(i:i).eq.' ' (b(0).eq. ' ' ---> ERROR, subscript less than 1). Now, I can think of better ways to write this particular item so that I don't get this error, but because it is part of larger code provided by a third party I'd rather not modify it. Yes, I can ask them to modify it but that is a whole other story.
My question is this (and I'm sure I'm not the first to ask), but why is the second condition evaluated at all if the first condition is FALSE?
If I compile/run the code in CVF6 I have no issue here and the code completes correctly. However, if I compile/run in IVF10, I get the subscript less than 1 error. Am I correct in assuming that this is being caused by the compiler? If so, is there a setting that I am missing in IVF10 that would turn off evaluation of 'downstream' conditions if the first turns out to be FALSE?
My apologies for being long winded but thanks in advance for any assistance.
We are currently moving some code from Compaq 6 to Intel 10 and I am having difficulty with a particular item of code in a subroutine provided by a supplier.
My issue concerns multiple conditions in 'do while' or 'if' type statements. The code in question follows.
i = len( b )
do while( i.ge.1 .and. b(i:i).eq.' ' )
i = i - 1
enddo
Let's assume that b = ' ', a four character string in which all characters are blank spaces. In the code above, 'i' will eventually become 0 (which is the desired result), and then the last time that the 'do while' evaluates the conditions, it will see i.ge.1 (0.ge.1 = FALSE) and b(i:i).eq.' ' (b(0).eq. ' ' ---> ERROR, subscript less than 1). Now, I can think of better ways to write this particular item so that I don't get this error, but because it is part of larger code provided by a third party I'd rather not modify it. Yes, I can ask them to modify it but that is a whole other story.
My question is this (and I'm sure I'm not the first to ask), but why is the second condition evaluated at all if the first condition is FALSE?
If I compile/run the code in CVF6 I have no issue here and the code completes correctly. However, if I compile/run in IVF10, I get the subscript less than 1 error. Am I correct in assuming that this is being caused by the compiler? If so, is there a setting that I am missing in IVF10 that would turn off evaluation of 'downstream' conditions if the first turns out to be FALSE?
My apologies for being long winded but thanks in advance for any assistance.
链接已复制
4 回复数
Thank you for the link. I assummed this was a topic that would have been well covered. I just wasn't able to come up with the correct combination of keywords in my search on this forum.
I had actually just found and entirely different thread on the same topic on usenet.
Anyway, as I said above, the code is not mine. It is provided by a third party supplier and I was looking for a quick and easy way to avoid going to them to fix their code.
I had actually just found and entirely different thread on the same topic on usenet.
Anyway, as I said above, the code is not mine. It is provided by a third party supplier and I was looking for a quick and easy way to avoid going to them to fix their code.
The programmer apparently wasthinking C/C++ boolian expression evaluation rules were in effect whereas Fortran rules are in effect. If you do change the code the replace the 4 statements with
i = LEN_TRIM( b )
Jim Dempsey
