Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29245 Discussions

Evaluation of logical expressions with mixed arguments

OP1
New Contributor III
380 Views
Hi,

Is it possible to have the compiler warn about the following situation:

...
LOGICAL :: FLAG
...
IF (FLAG == 'yes') THEN
...

In other words: the logical expression is made of a logical and a variable from another type. The compiler probably converts 'yes' into a logical (I suppose this is the same situation as having expressionswhere reals are mixed with integers or other kinds of variables, for instance).

So, is there a way to force the compiler to emit a warning in these situations? Or to prevent the compiler from converting argumentsof an expression based on the nature of the first argument?

Thanks,

Olivier
0 Kudos
2 Replies
Steven_L_Intel1
Employee
380 Views
Turning on standards checking will warn you about this. There are two things non-standard here. The first is the use of a character literal which is treated as a Hollerith constant in non-character contexts. Then there's the non-standard comparison of a logical to a numeric datatype.

There is not an option to disallow logical-numeric conversions, or one to warn speciifically about those. Both are things already on our "wish list".
0 Kudos
OP1
New Contributor III
380 Views

Ah, excellent, that did the trick. I am glad these are on your wish list - these programming errors can easily fly under the radar.

Thanks Steve!

Olivier

0 Kudos
Reply