Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

using integers as booleans

jayb
Beginner
652 Views

The legacy application that I am porting from g77 to Intel Fortran has many tests of the form:

IF (INTEGER_VAR)

and, since the FORTRAN is generated by RATFOR, many more tests of the form

IF (.NOT.(INTEGER_VAR)) CONTINUE . . .

I would like to detect these with a compiler warning, but even '-warn all' does not flag these.  Is there a flag that I can use?

Side note:  g77 detects these by default, but not when the -fugly flag is used.  And when you use that flag, it looks like some of the tests are executed incorrectly.

Thanks,
Jay

0 Kudos
4 Replies
mecej4
Honored Contributor III
652 Views

Use the -stand option. With this option, attempting to compile

subroutine tst(l,m)
integer, intent(in) :: l
integer, intent(out) :: m
m = .not. l
if (m) then
  write(*,*)' m is true'
else
   write(*,*)' m is false'
endif
return
end subroutine tst

gives the warning messages

ilog.f90(4): warning #6188: Fortran 2003 requires a LOGICAL data type in this context.   
m = .not. l
----------^
ilog.f90(5): warning #6188: Fortran 2003 requires a LOGICAL data type in this context.   
if (m) then
----^

 

0 Kudos
jayb
Beginner
652 Views

Fantastic!  Thanks much.

I'm almost frightened at the prospect of finding all the non-standard features . . . :--)

0 Kudos
TimP
Honored Contributor III
652 Views

Don't blame ratfor for this.  I've never seen that extension used with ratfor.  By the way, gfortran should be more reliable than g77 on many current platforms.  It may prove a useful intermediate step.

0 Kudos
jayb
Beginner
652 Views

Howdy.  No blame here.  I meant that since RATFOR translates something like:

if (integer_var) {
   do this }
rest of program

into something like:

IF (.NOT.(INTEGER_VAR)) GO TO  label
DO THIS
label: rest of program

as do most compilers that generate assembly language, or translators that generate C, this feature manifests itself with ".NOT" more often that with the "not"-less expression.

Regarding gfortran, it does not have the options that would be required to compile a working program from the FORTRAN 66/77 hybrid that the legacy program employs.  In a sense, Intel Fortran might theoretically be a stepping stone to an eventual gfortran implementation, as it supports the full range of FORTRAN/Fortran dialects.

JayB

0 Kudos
Reply