Re: Logicals converted to integers during reading



glen herrmannsfeldt wrote:
Dave Thompson wrote:
....
B, and IIRC very early C, had only & and | which fully evaluated when
in a normal expression context and shortcircuited when the (top)
expression in an IF, WHILE, etc. C (then) split them to provide
selectable shortcircuit. This is why both & | as well as && ||
(still) have low precedence in C, lower than often expected:
if( word_of_flags & 0x01F0 == 0x150 ){ do whatever }
is wrong -- it actually tests word_of_flags == 0 .

This will also happen in Fortran versions that allow logical operators
as bitwise operators on INTEGER values.

Not unless Fortran also begins to allow mixed-mode between
INTEGER (or BIT) and LOGICAL. The fortran version of the
above is:

if (word_of_flags .and. Z'01F0' == Z'150') then; whatever; endif

The conditional expression parses as:

word_of_flags .and. (Z'01F0' == Z'150')

Since the latter subexpression is of type LOGICAL (it's value
happens to be statically determinable to be .FALSE., but that's
not really relevant to the point in question) that's equivalent
to:

word_of_flags .and. .FALSE.

Which is simply illegal unless word_of_flags has type
LOGICAL. The above should just give a fatal error message.
Type mismatches are among the things that the standard requires
compliant implementations to (be able to) detect and report.

Fortran should *never* allow mixed-mode operations between
LOGICAL and any other type.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare


.



Relevant Pages

  • Re: communicating the name of a function to deep within the call tree
    ... it separates parts of two thirds, unless it really isn't two thirds. ... If Fortran had RATIONAL as a data type, ... generic programming. ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: F08 support of floating decimal?
    ... base 3 floating point is also rare. ... Legal for Fortran, though. ... trinary (where the digits are zero, one, and minus one) ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: Encapsulation
    ... Fortran 77 codebases that have no encapsulation or high-level structure ... Tolerating the same deficiencies would mean commercial suicide for us. ... I was talking about .NET code even though I also know about ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C style compound assignment operators
    ... In C and C++ they are either prefix or postfix, ... Remember that Fortran has a source form in which spaces ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)