假设您有一个包含大量变量,函数和子例程的Fortran 90模块.在您的USE陈述中,您遵循哪种惯例:
, only :语法显式声明您正在使用哪些变量/函数/子例程,例如 USE [module_name], only : variable1, variable2, ...?USE [module_name]?一方面,该only子句使代码更加冗长.但是,它会强制您在代码中重复自己,如果您的模块包含许多变量/函数/子例程,那么事情就会开始变得难以驾驭.
这是一个例子:
module constants
implicit none
real, parameter :: PI=3.14
real, parameter :: E=2.71828183
integer, parameter :: answer=42
real, parameter :: earthRadiusMeters=6.38e6
end module constants
program test
! Option #1: blanket "use constants"
! use constants
! Option #2: Specify EACH variable you wish to use.
use constants, only : PI,E,answer,earthRadiusMeters
implicit none …Run Code Online (Sandbox Code Playgroud)