测试导致的fortran分段错误 [英] segmentation fault created by fortran if tests

查看:79
本文介绍了测试导致的fortran分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下代码

    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为true,则不评估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分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆