如何在Fortran中使用多个模块而不发生名称冲突 [英] How does one use multiple modules in fortran without name clashes

查看:642
本文介绍了如何在Fortran中使用多个模块而不发生名称冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设在我的主程序中我想使用两个模块,模块a和模块b。这两个模块独立使用第三个模块,模块c。我是否认为名称冲突会导致错误?即模块c中所声明的实体将作为USE声明的结果在模块a和b中被有效地重新声明。如果是这样,一个人怎么解决这个问题?是否有可能在某处存在PRIVATE语句以避免麻烦?



感谢您花时间阅读此问题。



是的, 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屋!

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