最近看书,根据对module中public变量的理解写了个简单的演示程序,疑问我在程序的注释中已经说明。 
 
我的理解是 
module中public的变量在module contains中子程序可以直接使用,不需要定义 
在主程序或者其它module中只要use该module也可以直接使用,不需要定义 
不知道这样理解对不对,还请各位老师帮忙指点,先谢过! 
[Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode 
Module var
    Implicit None
    integer,public:: n
    integer,private:: i,j
    contains
    subroutine cal(n)
    integer n              !  n变量如果定义能顺利运行,若不定义,会出现如下错误
                                !  This name does not have a type, and must have an explicit type.   [N]
                                !  但是,n已经在module中定义为public变量了,为啥不能直接用
    j=0
    do i=1,n
        j=j+i
        write(*,*)i,n,j
    end do
    end subroutine cal
end Module var
program main
    use var
    Implicit None
    n=10
    call cal(n)
    pause
end 
 |