[英]segmentation fault created by fortran if tests
Suppose I have the following code 假设我有以下代码
IF (a.eq.0.or.M(a)) THEN
With a an integer and M(1:3) an array of logicals. 具有整数和M(1:3)的逻辑数组。 If a is equal to 0, then I expect the first test to catch it and the second one never to be evaluated.
如果a等于0,那么我希望第一个测试能够抓住它,而第二个测试永远不会被评估。 However, if I use the intel fortran compiler and compiles with
但是,如果我使用intel fortran编译器并使用
-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
if A is true then B is not evaluated. 如果A为true,则不评估B。 Does the Fortran standard explicitly requires that A and B can be evaluated even if does not impact the final result?
Fortran标准是否明确要求即使不影响最终结果也可以对A和B进行评估?
Fortran allows for, but does not guarantee , short-circuit evaluation of logical operators . Fortran允许但不保证逻辑运算符的短路评估 。 So to be safe, you will have to write your code under the assumption that each operand is evaluated.
因此,为了安全起见,您将必须在评估每个操作数的前提下编写代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.