在编写库来读取图像值时,我遇到以下问题:
我定义了一个名为realimage
的新类型。在此类型中引用了一个函数,该函数返回一个数组作为结果。
module typedefinition
implicit none
type realimage
integer :: byteorder = 0
contains
procedure :: initialize => initializereal
procedure :: pxvalues => pxvaluesreal ! Array valued function
end type realimage
contains
function pxvaluesreal(this, x, y) result(val)
implicit none
type(realimage) this
real val(5)
integer :: x, y
...
end function
end module
使用gfortran编译模块并使用image1%pxvalues(x,y)
调用该函数,我总是收到以下错误消息:
main.f95: In function ‘testtype’:
main.f95:15: internal compiler error
如果我直接在主程序(pxvaluesreal(image1,x,y))
中调用该函数,一切正常。
是否可以在类型定义中定义数组维度以告诉编译器,哪些是函数返回值的维数?
答案 0 :(得分:2)
内部编译器错误总是由于编译器错误。如果您使用的是最新版本的gfortran,您应该考虑查看他们的开放漏洞列表,并提交错误报告。
除此之外 - 您的代码不符合标准 - 传递的对象'this'必须是多态的(用CLASS而不是TYPE声明它)。否则,您对数组函数结果大小的指定是正确的 - 当您引用pxvalues绑定时,编译器知道函数结果的大小为5,因为它“知道”绑定与之关联的特定过程pxvaluesreal的接口。