Mic*_*l A 1 fortran gfortran fortran90
我有一个简单的Fortran 95程序
include "sandboxlib.f95"
program sandbox
implicit none
write(*, *) 'abc'
end program
Run Code Online (Sandbox Code Playgroud)
以及一个包含函数的简单模块
module sandboxlib
integer, parameter :: dp = kind(1.d0)
contains
function cumsum(mat, m, n) result(c)
implicit none
real(dp), intent(in) :: mat
integer, intent(in) :: m, n
integer i, j
real(dp), dimension(m, n) :: c
c(:, 1) = 0.d0
do i = 2, m
do j = 1, n
c(i, j) = c(i-1, j) + mat(i, j)
end do
end do
end function
end module
Run Code Online (Sandbox Code Playgroud)
我sandbox.f95用这个命令编译
/usr/bin/gfortran -O -std=gnu -Wfatal-errors -pedantic -Wall sandbox.f95 -o sandbox
Run Code Online (Sandbox Code Playgroud)
这会导致此错误
sandboxlib.f95:6.23:
Included at sandbox.f95:1:
function cumsum(mat, m, n)
1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'mat' at (1)
Run Code Online (Sandbox Code Playgroud)
你mat被宣布为标量
real(dp), intent(in) :: mat
Run Code Online (Sandbox Code Playgroud)
但你用它作为一个数组
c(i, j) = c(i-1, j) + mat(i, j)
Run Code Online (Sandbox Code Playgroud)
并且编译器将其解析为函数调用,并假设它mat()是一个函数.功能不能有intent.
我假设正确的事情是mat在声明中创建一个数组.像mat(:,:)或的东西mat(m,n).使用前者,您可以避免传递m和n作为参数.