Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran 2003中空参数的测试_Fortran_Fortran2003 - Fatal编程技术网

Fortran 2003中空参数的测试

Fortran 2003中空参数的测试,fortran,fortran2003,Fortran,Fortran2003,我声明了一个递归类型: type treeNode private class(treeNode), pointer :: left => null() class(treeNode), pointer :: right => null() contains procedure, non_overridable :: IsNull ! Returns true if link is null end type treeNode

我声明了一个递归类型:

type treeNode
private
  class(treeNode), pointer  :: left     => null()
  class(treeNode), pointer  :: right    => null()
contains 
 procedure, non_overridable    :: IsNull           ! Returns true if link is null
end type treeNode
我现在想实现“IsNull”函数

! ----
pure function IsNull( theNode )
  logical(LGT)  :: IsNull
  class(treeNode), pointer, intent(IN)  :: theNode

  IsNull = .not. associated( theNode )

end function IsNull
Gfortran抱怨指针属性: “错误:在(1)处传递的'isnull'的对象伪参数不能是指针”

如果删除指针属性,替换为目标属性(或不替换),则无法使用关联的构造。gfortran也不会让我测试与null()的等价性


问题:我如何测试实际参数是否为空?

你不能,反正不是这样。参见F2008第4.5.4.5节中描述的传递对象伪参数的特征。此外,如果用于引用过程的对象(对象%IsNull()中的对象)没有关联,那么您的程序可能会崩溃(您违反了F2008 12.5.1p2)


您真的需要IsNull过程进行类型绑定吗?你能用“常规”程序吗?

谢谢。根据我对规范的理解,我可以应用target属性并将null测试移动到调用方。请注意,我希望将类型中的指针保留为“private”。因此,我的实现必须彻底修改,以确保没有空目标作为参数传递。