Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran函数错误,与包含范围单元中的名称冲突_Fortran_Fortran90 - Fatal编程技术网

Fortran函数错误,与包含范围单元中的名称冲突

Fortran函数错误,与包含范围单元中的名称冲突,fortran,fortran90,Fortran,Fortran90,我刚学Fortran。这个简单的代码有什么问题 program combinatorial Implicit none integer :: m, n, Fact integer :: Com Write (*,*) 'inter 2 number for m and n' Read (*,*) m,n Com = Fact (m)/(Fact(n)*Fact(m-n)) Contains integer Function Fac

我刚学Fortran。这个简单的代码有什么问题

program combinatorial
    Implicit none
    integer :: m, n, Fact
    integer :: Com
    Write (*,*) 'inter 2 number for m and n'
    Read (*,*) m,n
    Com = Fact (m)/(Fact(n)*Fact(m-n))

    Contains
    integer Function Fact(t)
        Implicit none
        Integer, intent(IN) :: t
        integer :: i, Ans       
        Ans = 1
        Do i=1, t
            Ans=Ans * i
        End do
        Fact = Ans
    End Function Fact
End program combinatorial
我遇到的错误是:

combinatorial.f90(10): error #6626: The name of the internal procedure conflicts with a name in the encompassing scoping unit.   [FACT]
    integer Function Fact(t)
-------------------------^
compilation aborted for combinatorial.f90 (code 1)

由于
事实
在程序中是
包含
的,编译器将自动生成一个接口。通过声明一个名为
Fact
integer
东西,你给编译器的指令是冲突的,它不喜欢这样。只需从行中删除
事实

integer :: m, n, Fact
编译器引用的
包含作用域单元是包含(或包含)函数的程序

另外,在函数定义中不需要使用变量
Ans
。你可以简单地写

integer Function Fact(t)
    Implicit none
    Integer, intent(IN) :: t
    integer :: i       
    Fact = 1
    Do i=1, t
        Fact = Fact * i
    End do
End Function Fact
除非在
function
语句上使用
result
子句,否则编译器的行为就像创建了一个与函数同名的变量来返回函数的结果一样