module - Fortran主程序子例程可以链接模块变量但不能链接模块子例程?
问题描述
我有一个我制作的模块:
module my_sweet_module
complex, allocatable, volatile, save, private :: buffer_mem
integer mod_int1, mod_int2
contains
subroutine mod_sub1
include 'CRAPPY_OLD_IMPLICIT_PARAMETER_FILE'
<other code>
allocate(buffer_mem(CRAPPY_PARAMETER))
<more code>
end subroutine mod_sub1
end module my_sweet_module
当我在声明use
之后的主文件中的这个模块时,无论我在什么范围内program
,我都可以引用我在模块中声明的 - 事实上,由于名称冲突,我不得不重构我的代码以重命名任何实例.integers
mod_int1
但是,任何时候我想mod_sub1
在我的主文件中的子例程中使用,我必须use my_sweet_module
在子例程的顶部有一个,否则当我尝试编译时会出现“未定义的引用”错误。
我的主文件示例:
program my_prog
include 'ANOTHER_CRAPPY_OLD_IMPLICIT_PARAMETER_FILE'
use my_sweet_module
<code>
end program my_prog
subroutine main_sub1(args)
include 'EVEN_MORE_CRAPPY_OLD_IMPLICIT_PARAMETER_FILE'
!use my_sweet_module !uncomment this to fix errors
integer sub_int1
sub_int1=mod_int1+1 !Compiler is happy; doesn't give any error, even if it "should"
call mod_sub1 !compiler is unhappy, says "undefined reference to 'mod_sub1_'"
end subroutine main_sub1
笔记:
- 我不能
implicit none
在我的模块或我的主文件中使用,因为我将这个模块固定在一些古老的代码上,这些代码在include
d 文件中到处使用隐式类型,我也需要在我的模块中使用 - 如果重要,在 Linux 中使用 ifort 版本 5.243 进行编译
mod_sub1
没有重复使用名称,也没有在任何地方被重新用作名称
我自己“解决”了我的问题,但我完全糊涂了。我要么不需要use
到处都有,或者如果我不这样做,编译器不应该能够链接全局整数?两者都mod_int1
应该mod_sub1
超出范围,或者两者都不应该——错误不应该像这样混合和匹配。
解决方案
推荐阅读
- python - 使用熊猫搜索字符串包含在多列中的有效方法
- python - AttributeError: __enter__ 语音识别
- c - C程序打印一个系列
- python - 使用 Python 更新 DynamoDB 表中的 JSON 记录
- java - Android Studio-我正在尝试从 firebase 数据库中搜索用户,但出现错误
- react-native - iOS 模拟器内的 Expo React Native 应用程序不断使用 socket.io 重新连接
- laravel - 通过 NS 记录在不同主机上的子域
- swift - 快速从函数返回值
- javascript - 以反应形式上传图像
- couchdb - 如何从 couchDB 中的多个数据库中获取记录