写入假定大小的数组会导致“不得省略上限...". [英] Writing assumed-size array causes "upper bound shall not be omitted..."
本文介绍了写入假定大小的数组会导致“不得省略上限...".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写代码,以添加一个封闭源有限元素框架,该框架迫使我(由于依赖某些旧的F77样式方法)在一个地方依赖于假定大小的数组.
I am writing code to add on a closed-source Finite-Element Framework that forces me (due to relying on some old F77 style approaches) in one place to rely on assumed-size arrays.
是否可以将假定大小的数组写入标准输出,而不管其大小如何?
这不起作用:
module fun
implicit none
contains
subroutine writer(a)
integer, dimension(*), intent(in) :: a
write(*,*) a
end subroutine writer
end module fun
program test
use fun
implicit none
integer, dimension(2) :: a
a(1) = 1
a(2) = 2
call writer(a)
end program test
抛出Intel Fortran编译器
With the Intel Fortran compiler throwing
error #6364: The upper bound shall not be omitted in the last dimension of a reference to an assumed size array.
推荐答案
编译器不知道假定大小的数组有多大.它只有第一个元素的地址.您有责任告诉您它有多大.
The compiler does not know how large an assumed-size array is. It has only the address of the first element. You are responsible to tell how large it is.
write(*,*) a(1:n)
等效地,您可以使用显式大小的数组
Equivalently you can use an explicit-size array
integer, intent(in) :: a(n)
然后您就可以
write(*,*) a
这篇关于写入假定大小的数组会导致“不得省略上限...".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文