James Van Buskirk wrote:But you cannot assume that .false. is 0 and .true. is 1. I know at least
> As i have had occasion to point out previously, if the compiler
> allows free mixing of logical and integer types, then, assuming that
> 0 is the canonical .FALSE. value and 1 is a .TRUE. value:
one compiler were .true. is -1.
> if x is .TRUE., then 1 .AND. x must be .TRUE. as well, so theWell, you assume some bitwide handling of
> low bit of x must be set. Similarly, if x is .FALSE. then
> 1 .AND. x must be .FALSE., so the low bit of x must be clear.
<logical-expr> .AND. <integer-expr>
where one then looks afterwards only at a single bit (i.e. treats it as
logical). However, the compiler is not necessarily the case. For
instance, in C99 it is not possible as the resulting expression is "int"
and if you do "if(<int-expr>)" you may not look at a single bit.
By contrast, a Fortran compiler is completely free to handle it as it
> Also .NOT. 0 is -1, so the canonical value of .TRUE. must be -1.I have to admit that I do not understand this part. But I disagree with
> Now, this could be consistent with the C _Bool type provided the
> C compiler considered only the low bit of an _Bool to contribute
> to its value and set the high bits when creating the true _Bool
> value. Unfortunately C compilers paradoxically examine all bits
> of an _Bool when determining whether it is false (all bits zero)
> or true (anything else).
I don't see why .NOT. 0 should be -1. You could also flip only the other
Of course, that assumes that you either always look only at the single
That assumption you can do in Fortran for a chosen implementation.
But that assumption you can also do in C as you know that _Bool only has
The reason that C compilers often look at more than a single bit is that
"The result of the logical negation operator ! is 0 if the value of its
But if the compiler knows that "E" is always either 0 or 1, it can flip
"When any scalar value is converted to _Bool, the result is 0 if the
I think for conditions, it doesn't matter that much whether one checks
> The C compiler could follow the extendedI am lost again. Why should a compiler set C_Bool to -1? It just has to
> Fortran behavior and still conform to the standard, but this choice
> is never made, so any Fortran compiler that permits mixing of real
> and logical expressions must set C_BOOL to -1
comply to C99 by ensuring that only 0 and 1 are passed to the register.
Or alternatively, the same-vendor C compiler has to handle it in the
same way. My impression is that this works rather well.
However, it doesn't work well if one mixes compilers of two vendors. If
That's actually a real-world problem. But I still maintain that this is
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.