Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Legal fortran?

lklawrie
Beginner
827 Views
I don't think this is legal Fortran, but IVF didn't complain:

ELSE IF(-25.d0 < CoilInletTemp <=0.0d0) THEN

gfortran did complain.

any comments?

Is this kind of statement legal in c, c++, basic?

(Always trying to figure out where our developers get their syntax).

probably is legal in things like mathlab, Mathematica

Linda
0 Kudos
6 Replies
TimP
Honored Contributor III
827 Views

If a compiler accepts this, it's likely done via the extension where logical expressions can be treated as integer. Even then it looks ambiguous. The behavior isn't lkely to resemble what the author intended, no matter what "language" is in use. Yes, it's probably "legal" in C and C++; I hope not in BASIC. ifort should complain if you set -stand.
0 Kudos
Steven_L_Intel1
Employee
827 Views
This statement is not legal in Fortran. Intel Fortran will accept it, though, via its extension of doing automatic conversion between numeric and logical. It is probably interpreted as:

(23.d0 < CoilInetTemp) <= 0.0D0

where the expression in parentheses yields either a .TRUE. or .FALSE. value. This is then converted to REAL(8) using -1 for .TRUE. and 0 for .FALSE.. If you enable standards checking, it would complain.

This extension has its roots more than three decades ago, but I have been agitating for it to be disabled by default. I will bring this up again.
0 Kudos
TimP
Honored Contributor III
827 Views
If you enable standards checking, it would complain.

This extension has its roots more than three decades ago, but I have been agitating for it to be disabled by default. I will bring this up again.

I'm in favor. I haven't seen any customers wanting that extension.
0 Kudos
lklawrie
Beginner
827 Views
I agree -- see no reason for allowing that.

I did not see if CVF accepted it. gfortran said "junk". did not check g95 with it either (yet).

in any case, i don't think the compiler is going to do what the developer intended/wants.

Thanks.

Linda
0 Kudos
JVanB
Valued Contributor II
827 Views
Obviously it's legal Fortran, and a bug for gfortran to reject it.
[bash]module M
   implicit none
   type T
   end type T
   interface operator(<)
module procedure op end interface operator(<) interface operator(<=) module procedure op2 end interface operator(<=) contains function op(x,y) double precision, intent(in) :: x type(T), intent(in) :: y double precision op op = -1 end function op function op2(x,y) type(T), intent(in) :: x double precision, intent(in) :: y double precision op2 op2 = -1 end function op2 end module M program P use M implicit none type(T) CoilInletTemp IF(.FALSE.) THEN ELSE IF(-25.d0 < CoilInletTemp <=0.0d0) THEN write(*,*) 'Test successfully passed.' END IF end program P [/bash]
0 Kudos
Steven_L_Intel1
Employee
827 Views
Harumph. Yes, if you define your own operators it can be legal, but I have to assume that wasn't done in Linda's example.
0 Kudos
Reply