2012-07-13 34 views
0

在編寫庫來讀取圖像值時,存在以下問題: 我定義了一個名爲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)),一切工作正常。

是否可以在類型定義中定義數組維以便告知編譯器,哪些是函數返回值的大小?

回答

2

內部編譯器錯誤總是由於編譯器錯誤。如果您使用的是最新版本的gfortran,則應考慮查看其開放漏洞列表並可能提交錯誤報告。

除此之外 - 您的代碼不符合標準 - 傳遞的對象this必須是多態的(用CLASS而不是TYPE來聲明)。否則,您指定的數組函數結果的大小是正確的 - 當您引用pxvalues綁定時,編譯器知道函數結果的大小爲5,因爲它'知道'該綁定關聯的特定過程pxvaluesreal的接口。

相關問題