Fortran本身的界面会产生令人讨厌的错误 [英] Fortran interface to itself produces annoying error

查看:70
本文介绍了Fortran本身的界面会产生令人讨厌的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经存在了好几年,但是我从未听说过有一个好的解决方案.

This problem has been around for a few years, but I never heard of a good solution to it.

如果Fortran子例程包含具有自身接口的模块

If a Fortran subroutine includes a module with an interface to itself

subroutine stuff(nz,z,dt)
  use allinterfaces
  ...

发生错误

错误:在(1)处导入的模块"allinterfaces"的"stuff"也是当前程序单元的名称
Error: 'stuff' of module 'allinterfaces', imported at (1), is also the name of the current program unit

要修复它,我必须声明

subroutine stuff(nz,z,dt)
  use allinterfaces, except_this_one => stuff
  ...

这是荒谬的行为,令人讨厌,因为我喜欢在模块中包含所有接口.如果这不是编译错误,或者至少应该有一个except_itself

This is absurd behavior and annoying since I like to include all interfaces in a module. It would be helpful if this was not a compile error, or at least there should be an except_itself

我正在使用的编译器是gfortran版本4.8.2(GCC),但我怀疑这是编译器的错.

The compiler I am using is gfortran version 4.8.2 (GCC), but I doubt this is the compiler's fault.

有人知道这种行为背后的原因,还是更实际的解决方案?

Does anyone understand the rational behind this behavior, or a more practical solution?

编译器可以使用此信息来检查模块中定义的接口是否与实际的子例程匹配.因此,这比可能要差两个级别.忽略信息是错失的机会;将其视为错误会适得其反.

The compiler could use this information to check whether the interface defined in the module matches the actual subroutine. So it's two levels worse than it could be. Ignoring the information is a missed opportunity; treating it as an error is counterproductive.

推荐答案

此行为由Fortran标准指定.标准委员会讨论了放宽所谓自我接口"的限制,但最终拒绝了.我不记得具体情况.由于该标准禁止使用它,因此要求编译器能够对其进行诊断,并且大多数默认情况下都可以执行.

This behavior is specified by the Fortran standard. The standards committee discussed relaxing the restriction, termed "interface to self", but ultimately rejected it. I don't remember the specifics. Since the standard forbids it, compilers are required to be able to diagnose it and most do by default.

仅当尝试逐步更新F77样式的程序以使用显式接口时,您才会遇到此问题.我会注意到,英特尔Fortran(也许还有gfortran)具有一项功能会自动为您检查此类接口(在ifort中是-warn接口).

You'd encounter this problem only when trying to incrementally update an F77-style program to use explicit interfaces. I'll note that Intel Fortran, and maybe gfortran as well, has a feature that will automatically check such interfaces for you (in ifort it's -warn interface).

也许更好的方法是将您的过程放在模块中.

Perhaps the better approach is to put your procedures in modules.

这篇关于Fortran本身的界面会产生令人讨厌的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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