为什么这种类型无法访问?

Sig*_*gyF 4 fortran scope gfortran

我正试图从fortran函数返回一个类型.这是代码.

module somemodule
implicit none
! define a simple type
type sometype
   integer :: someint
end type sometype
! define an interface 
interface
   ! define a function that returns the previously defined type
   type(sometype) function somefunction()
   end function somefunction
end interface
contains
end module somemodule
Run Code Online (Sandbox Code Playgroud)

在gfortran(4.4和4.5)中,我收到以下错误:

错误:无法访问(1)处的"somefunction"功能的类型

我将文件编译为:

gfortran -c ./test.F90
Run Code Online (Sandbox Code Playgroud)

我尝试将该类型明确公开,但这没有帮助.我打算使用某种功能的交流版本,这就是我把它放在接口部分的原因.

为什么这种类型无法访问?

M. *_* B. 6

在函数定义中添加导入可以解决此问题.由于许多人认为语言设计中存在错误,因此定义不会在接口内部继承."导入"优先于此以实现合理的行为.

interface
   ! define a function that returns the previously defined type
   type(sometype) function somefunction()
   import
   end function somefunction
end interface
Run Code Online (Sandbox Code Playgroud)