如何在Fortran中使用多个模块而不发生名称冲突 [英] How does one use multiple modules in fortran without name clashes
问题描述
感谢您花时间阅读此问题。
是的, c中的公共实体
code>将在 a
和 b
中与使用关联,然后在主程序中使用,
模块c
整数型
结束模块c
模块a
使用c
结束模块a
模块b
使用c
结束模块b
程序main
使用
使用b
!使用c
int = 1
结束程序
您的困惑可能是模块c中的被声明的实体将被有效地重新声明:存在关联,但使用相同的声明。这与C头文件形成对比。
Suppose in my main program I want to use two modules, module a and module b. These two modules independently use a third module, module c. Am I correct in thinking that name clashes will result? i.e the declared entities in module c will effectively be redeclared in both modules a and b as a result of the USE statements. If so, how does one get around this? Is it possible to have a PRIVATE statement somewhere to avoid the trouble?
Thanks for taking the time to read the question.
Name clashes won't result.
Yes, public entities in c
will be use-associated in a
and b
, and then in your main program, but no ambiguity will be introduced.
module c
integer int
end module c
module a
use c
end module a
module b
use c
end module b
program main
use a
use b
! use c
int = 1
end program
Your confusion may be "declared entities in module c will effectively be redeclared": there is association, but the same declaration is used. This is in contrast with, say, C header files.
这篇关于如何在Fortran中使用多个模块而不发生名称冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!