为什么ifort-warn都在接口不匹配时抛出错误? [英] Why does ifort -warn all throw errors on interface mismatch?

查看:0
本文介绍了为什么ifort-warn都在接口不匹配时抛出错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是一些示例代码:

! Author: Svetlana Tkachenko svetlana@members.fsf.org
! 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不包括错误。

我知道我只能修复代码,但我正在尝试为旧代码库设置测试套件,并且我希望在开始更改代码之前能够运行带有警告的编译测试。

推荐答案

选项-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 

在存在缺省隐式类型规则时是两件非常不同的事情。它们可能与没有可执行语句(等等)具有相同的最终效果。但它们的特点却大相径庭。

这篇关于为什么ifort-warn都在接口不匹配时抛出错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆