------- Comment #6 from tobi at gcc dot gnu dot org  2005-11-05 23:06 -------
I did some further research, and while g77 didn't seem to have documented any
of the details of how LOGICALs are implemented, we have the following in
gfortran.texi:755:
----
@node Implicitly interconvert LOGICAL and INTEGER
@section Implicitly interconvert LOGICAL and INTEGER
@cindex Implicitly interconvert LOGICAL and INTEGER

As a GNU extension for backwards compatibility with other compilers,
@command{gfortran} allows the implicit conversion of LOGICALs to INTEGERs
and vice versa.  When converting from a LOGICAL to an INTEGER, the numeric
value of @code{.FALSE.} is zero, and that of @code{.TRUE.} is one.  When
converting from INTEGER to LOGICAL, the value zero is interpreted as
@code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
----
And this is indeed true and consistent with what g77 does:
[EMAIL PROTECTED]:~/src/tests> cat ugly.f
      LOGICAL L
      DO i=0,5
        L = i
        PRINT *, l
      END DO
      END
[EMAIL PROTECTED]:~/src/tests> gfortran ugly.f
 In file ugly.f:3

  L = i
     1
Warning: Extension: Conversion from INTEGER(4) to LOGICAL(4) at (1)
[EMAIL PROTECTED]:~/src/tests> LD_LIBRARY_PATH=~/usr/lib ./a.out
 F
 T
 T
 T
 T
 T
[EMAIL PROTECTED]:~/src/tests> g77 ugly.f -fugly-logint
[EMAIL PROTECTED]:~/src/tests> ./a.out
 F
 T
 T
 T
 T
 T
[EMAIL PROTECTED]:~/src/tests> 

(The INTEGER -> LOGICAL conversion is implemented as "i = l != 0" as verified
by looking in the tree dumps.)
I think we should be consistent.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22495

Reply via email to