I know in C, integers used as logical expressions evaluate anything != 0 as TRUE, and 0 as FALSE. I had assumed (or maybe I was dreaming) that Fortran did the same. I always tell people never to pass a Fortran logical to a C function and expect the value to be 0 or 1, because in my experience it is usually a random number or 0.
HOWEVER, I'm seeing something now that is a bit perplexing. I have a local INTEGER*4 variable that I set to the result of a bitwise expression:
I = IAND( UPDATE_CLASS, 512 ) IF ( I ) THEN WRITE( *, * ) 'I WAS TRUE' END IF
When UPDATE_CLASS is 512, I never get the printout. Upon examining the generated assembler, we have:
% I = IAND( UPDATE_CLASS, 512 ) mov eax, dword ptr [0x111111] and eax, 0x200 mov dword ptr [0x123123], eax % IF ( I ) THEN test al, 0x1 jz 0x7543212
....so, if my assembler interpretation is correct, it looks like it's only checking to see if the first bit of the integer value is set, not any bit. Is this expected behavior? I tried asking The Google, but I can't seem to find any documentation on treating integers as logical expressions.