Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!cfisun!stellar!keith From: keith@stellar.UUCP (Keith Crews @stellar) Newsgroups: comp.lang.fortran Subject: extensions to logical variables Keywords: vax,logicals Message-ID: <31660@stellar.UUCP> Date: 26 Apr 89 12:53:24 GMT Organization: Stellar Computer Inc. Newton, MA Lines: 76 I have some questions about common fortran extensions to logical variables. Some fortrans (such as vms) have extended logicals so that they behave a lot like integers in most contexts. For example, you can assign them values other than 0 and -1 (or whatever the conventional values for false and true are) and you can do arithmetic on them. However if you have assigned values to them other than 0 or -1 you then get some strange results. You get logical variables that are neither true nor false (kind of like ieee nans) and you can have 2 non-zero logicals variables that don't have the same truth value. The basic problem I have with the vax implementation is that I think that a logical variable should always be true or false. You can do this by forcing a conversion to 0 or -1 when assigning to them (although this can be defeated by using equivalences) or you can treat all non-zero logicals as being true and only 0 as being false. However, the vax and other compilers seem to have extended logicals by allowing them to act like integers in many contexts while leaving the underlying implementation alone and the result is that using extensions to logicals can result in some surprising results. My questions are: 1) Do people depend on having logicals that are neither true nor false? 2) What would people consider a consistent set of semantic rules for these extensions to logicals? 3) Should .eq. and .eqv. behave identically with logical operands or should .eq. do integer comparisons and .eqv. check for both zero or both non-zero? If you allow 2 distinct non-zero logicals to not be equal (.eq. different from .eqv. in 3 above) then you have another problem where the 2 expressions below may evaluate differently: l1 = 3 l2 = .true. if (l1 .eq. .true.) ... if (l1 .eq. l2) ... However, if you evaluate them the same then you are incompatible with vms fortran which seems like a dubious idea. I guess the real issue is whether I have missed a unifying idea under- lying the vms implementation. Here are a couple of examples: This prints 0 on the vax: logical l1 l1 = 3 i = 0 if (l1 .eq. .true.) then i = 1 endif if (l1 .eq. .false.) then i = 2 endif print *, i end This prints 2 on the vax and 1 on the sun: logical l1, l2 l1 = 3 l2 = 4 i = 0 if (l1 .eqv. l2) then i = 1 endif if (l1 .neqv. l2) then i = i + 2 endif print *,i end -- Keith Crews Stellar Computer Inc. 95 Wells Avenue, Newton, MA 02159