我是否需要将implicit none每个功能和子程序放入其中?
或者它是否足以将它放在包含这些函数和子例程的模块的开头?
或者它是否足以将它放在使用这些模块的程序的开头?
从观察其他人的工作代码,implicit none包含在所有这些地方.我不确定这是否是冗余的,因为implicit none从子程序中删除仍然编译并产生相同的输出.
顺便说一句,我正在使用gfortran fortran 90.
如何避免在子程序中重复声明具有常量值的变量?
例如:
program test
implicit none
integer :: n
integer :: time
print*, "enter n" ! this will be a constant value for the whole program
call Calcul(time)
print*, time
end program
subroutine Calcul(Time)
implicit none
integer :: time
! i don't want to declare the constant n again and again because some times the subroutines have a lot of variables.
time = n*2
end subroutine
Run Code Online (Sandbox Code Playgroud)
有时,有很多由用户定义的常量,我会制作很多使用这些常量的子例程,所以我想存储它们并使用它们,而不是一次又一次地重新定义它们。