Implicit conversion integer <--> logical in Fortran if statement

前端 未结 1 1154
春和景丽
春和景丽 2021-01-15 13:15

I have some legacy Fortran code which I was asked to analyze and translate to a modern language. I don\'t know which compiler was used in the past to compile the code, so fo

1条回答
  •  离开以前
    2021-01-15 14:00

    This is not possible in GFortran. The manual states:

    However, there is no implicit conversion of INTEGER values in if-statements, nor of LOGICAL or INTEGER values in I/O operations.

    You are only able to perform implicit conversions in assignments like your

      integer :: var
      var = .true.
    

    but even there you must be very careful. It is not standard conforming and the value var will differ between compilers. Intel used to use -1 (all bits set to 1), unless -standard-semantics was chosen, for .true., but gfortran uses +1 as in the C language. New versions of Intel Fortran changes the default. The other direction is even trickier, there might be values which are neither .true. nor .false..

    0 讨论(0)
提交回复
热议问题