2016-03-02 45 views
1

下面是一些示例代碼:爲什麼ifort - 在接口不匹配時拋出所有拋出錯誤?

! Author: Svetlana Tkachenko [email protected] 
! License: GPLv3 or later 

subroutine myprint(var) 
! integer :: var 
! print *, 'Hi, my ', var 
end subroutine 

module testing 
    type triangle 
     integer :: point(3) 
    end type 
end module 

program main 
    use testing 
    type(triangle) :: mytriangle 
    mytriangle%point(1)=5 
    call myprint(mytriangle%point(1)) 
end program 

它正常工作與ifort -c file.f90,但ifort -warn all -c file.f90導致錯誤:

blah.f90(4): warning #6717: This name has not been given an explicit type. [VAR] 
subroutine myprint(var) 
-------------------^ 
blah.f90(4): remark #7712: This variable has not been used. [VAR] 
subroutine myprint(var) 
-------------------^ 
blah.f90(19): error #6633: The type of the actual argument differs from the type of the dummy argument. [POINT] 
    call myprint(mytriangle%point(1)) 
---------------------------^ 
compilation aborted for blah.f90 (code 1) 

爲什麼-warn all拋出一個錯誤?該手冊頁特別說明all不包括錯誤

我知道我只能修復代碼,但我正在嘗試爲遺留代碼庫設置測試套件,並且希望能夠在開始進行代碼更改之前運行帶有警告的編譯測試。

+0

您可以(應該)在實際支持論壇上詢問供應商,瞭解其具體行爲的原因。 –

+0

我只是假設你知道'var'在子程序中隱含地是'real' ... –

回答

5

選項-warn all包含選項-warn interfaces激勵對可以確定這些接口的外部過程進行接口檢查。這通常用於通過選項-gen-interfaces編譯的獨立文件中的外部程序生成的接口。

正是這個選項-warn interfaces負責錯誤信息。這可以檢查外部子程序的接口,因爲該子程序與引用它的程序位於同一個文件中。您有兩種選擇,那麼:

  • 在不同的文件中有外部子程序,沒有用-gen-interfaces編譯;
  • 請勿使用-warn interfaces

對於後者,你可以使用

ifort -warn all -warn nointerfaces ... 

有其他警告,但接口檢查。

然而,每個人都應該有匹配的接口。應當注意的,那麼,

subroutine myprint(var) 
! integer :: var 
end subroutine 

subroutine myprint(var) 
    integer :: var 
end subroutine 

是在默認的隱式類型規則存在兩個非常不同的事情。它們可能具有與沒有可執行語句(等等)相同的最終效果,但其特性完全不同。

+0

感謝您的解釋。它仍然看起來像一個錯誤,這被報告爲一個錯誤,而不是一個警告,對吧? – naught101

+0

我不會稱它爲編譯器中的錯誤。您正在調用帶有隱式接口的過程,並要求編譯器檢查(使用隱含的「-warn interfaces」選項)接口是否匹配。它在某種意義上(我收集到)假裝接口是顯式的(參見文檔,包括'-gen-interfaces'選項,並查看生成的模塊文件:它就好像涉及模塊一樣),這確實使這是一個錯誤,而不是一個警告。是的,我可以看到有這個警告會很好... cont – francescalus

+0

...並且有很多時候,當以某種方式進行黑客接口時,各種調用變得更加簡單,但是編譯器允許您選擇是否使這個錯誤成爲錯誤:您可以在「警告階段」中將此然後在沒有接口檢查的情況下重新編譯,作爲下一步。 – francescalus

相關問題