Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unusual IF statement processing in XLFortran under AIX

Status
Not open for further replies.

eggsauce

Programmer
Mar 11, 2003
2
GB
I am using XL Fortran v7.1.1.2 under AIX 5.1 and have some unusual behaviour inside an if statement.

I have discovered that the following fortran IF statement does not work the way it appears to read
(code in the if block is NEVER executed):

if ((someFunction(someArg) .eqv. .true. &
.or. someParameter >= 2)) then

The syntax that works is:
if ((someFunction(someArg) .eqv. .true. ) &
.or. someParameter >= 2) then

Note the different bracket positioning.

The syntax details do not clearly explain why the first statement does not work. I have speculated that perhaps the logical expression is being converted into an arithmetic due to the presence of the brackets but other than that it is a bit of a mystery.

Has anyone else also observed this behaviour or have an alternative explanation?

thanks in advance
John
 
It is basically operator precedence. The order is

.not.
.and.
.or.
.eqv. or .neqv.

if you have

a .and. b .or. c

by default, the grouping is

(a .and. b) .or. c

Similarly if you have

a .eqv. b .or. c

the grouping is

a .eqv. (b .or. c)

When in doubt, put in brackets. Anyway testing for .eqv. .true. is a waste of time. It is simpler if you have

if (someFunction(someArg) .or. someParameter .ge. 2)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top