Re: printing logical variables as "true" and "false"



"Paul Van Delst" <Paul.vanDelst@xxxxxxxx> wrote in message
news:dmi229$1on$1@xxxxxxxxxxxxxxxxxxxxx

> Slightly off topic, but in IDL:

> F => Zero and even values (e.g. -4, -2, 0, 2, 4, etc)
> T => Odd non zero values (e.g. -3, -1, 1, 3, 5, etc)

> (which I can't stand, btw.)

Actually, the DEC family of Fortran compilers did this, too.
The massive advantage of the LSB defining LOGICAL values like
this is that bitwise logical operations have the effect of
Fortran LOGICAL operations. I consider it probable that
many old-school compilers (i.e. ones that have roots predating
MIL-STD 1753) behave this way so as to permit masking
expressions. The difference in behavior becomes apparent
when mixed-language programming of bit-swizzling via
TRANSFER. One can get ugly results when Fortran processors
use the C-style (value of x is "x /= 0") int as boolean:
you can have both a and b evaluate as .TRUE., but a .AND. b
evaluate as .FALSE.

program logical_test
implicit none
logical a, b

a = transfer(1,a)
b = transfer(2,b)
write(*,*) a, b, a .AND. b
end program logical_test

Output with LF95 v. 5.70f:

T T F

Output with CVF v. 6.6C3

T F F

Output with g95 gcc version 4.0.1 (g95!) Sep 1 2005:

T T T

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


.