gpt4 book ai didi

compiler-errors - 为什么 ifort -warn all 在接口(interface)不匹配时抛出错误?

转载 作者:行者123 更新时间:2023-12-02 10:43:42 25 4
gpt4 key购买 nike

这是一些示例代码:

! 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对可以确定此类接口(interface)的外部程序进行接口(interface)检查。这通常用于使用选项 -gen-interfaces 编译的单独文件中的外部过程生成的接口(interface)。 .

就是这个选项-warn interfaces负责错误消息。这能够检查外部子程序的接口(interface),因为该子程序与引用它的程序位于同一文件中。那么你有两个选择:

  • 将外部子程序放在一个不同的文件中,而不是用 -gen-interfaces 编译;
  • 不要使用 -warn interfaces .

  • 对于后者,您可以使用
    ifort -warn all -warn nointerfaces ...

    有所有其他警告,但接口(interface)检查。

    然而,其中每一个都更可取的是具有匹配的接口(interface)。那么需要注意的是,
    subroutine myprint(var) 
    ! integer :: var
    end subroutine


    subroutine myprint(var) 
    integer :: var
    end subroutine

    在存在默认的隐式类型规则的情况下,这是两个非常不同的事情。它们可能具有相同的最终效果,但没有可执行语句(等),但特性却大不相同。

    关于compiler-errors - 为什么 ifort -warn all 在接口(interface)不匹配时抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35740299/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com