fortran if 测试创建的分段错误 [英] segmentation fault created by fortran if tests
问题描述
假设我有以下代码
IF (a.eq.0.or.M(a)) THEN
使用一个整数和 M(1:3) 一个逻辑数组.如果 a 等于 0,那么我希望第一个测试能够捕获它,而第二个测试永远不会被评估.但是,如果我使用 intel fortran 编译器并使用
With a an integer and M(1:3) an array of logicals. If a is equal to 0, then I expect the first test to catch it and the second one never to be evaluated. However, if I use the intel fortran compiler and compiles with
-check all
然后我遇到了分段错误.没有此调试选项不会发生错误.这是标准行为吗?对于许多语言,手册中明确指出对于
then I got a segmentation fault. No error occurs without this debugging option. Is it a standard behavior? For many languages it is said explicitly in the manual that for
IF (A.or.B) THEN
如果 A 为真,则不评估 B.Fortran 标准是否明确要求即使不影响最终结果也可以评估 A 和 B?
if A is true then B is not evaluated. Does the Fortran standard explicitly requires that A and B can be evaluated even if does not impact the final result?
推荐答案
Fortran 允许,但不保证对逻辑运算符进行短路评估.因此,为了安全起见,您必须在假设每个操作数都被评估的情况下编写代码.
Fortran allows for, but does not guarantee, short-circuit evaluation of logical operators. So to be safe, you will have to write your code under the assumption that each operand is evaluated.
这篇关于fortran if 测试创建的分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!