Re: Logicals converted to integers during reading
- From: "James Giles" <jamesgiles@xxxxxxxxxxxxxxxx>
- Date: Mon, 14 Aug 2006 18:27:17 GMT
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
.
- Follow-Ups:
- Re: Logicals converted to integers during reading
- From: glen herrmannsfeldt
- Re: Logicals converted to integers during reading
- References:
- Logicals converted to integers during reading
- From: Bálint Aradi
- Re: Logicals converted to integers during reading
- From: Steve Lionel
- Re: Logicals converted to integers during reading
- From: beliavsky
- Re: Logicals converted to integers during reading
- From: glen herrmannsfeldt
- Re: Logicals converted to integers during reading
- From: Craig Powers
- Re: Logicals converted to integers during reading
- From: glen herrmannsfeldt
- Re: Logicals converted to integers during reading
- From: James Giles
- Re: Logicals converted to integers during reading
- From: glen herrmannsfeldt
- Re: Logicals converted to integers during reading
- From: Dave Thompson
- Re: Logicals converted to integers during reading
- From: glen herrmannsfeldt
- Logicals converted to integers during reading
- Prev by Date: Re: operator precedence in Fortran 2008 draft
- Next by Date: Re: Logicals converted to integers during reading
- Previous by thread: Re: Logicals converted to integers during reading
- Next by thread: Re: Logicals converted to integers during reading
- Index(es):
Relevant Pages
|