在Fortran中分配零大小的数组时,我得到了令人费解的行为。
以下是代码:
program test_zerosized
implicit none
integer, allocatable :: a(:),b(:)
allocate(a(0))
print *, ' a lower bound = ',lbound(a,1)
print *, ' a upper bound = ',ubound(a,1)
allocate(b(0:0))
print *, ' b lower bound = ',lbound(b,1)
print *, ' b upper bound = ',ubound(b,1)
return
end program test_zerosized
产生以下输出:
a lower bound = 1
a upper bound = 0
b lower bound = 0
b upper bound = 0
我的编译器(gcc/gfortran 6.2.0)是否符合标准?我不明白为什么lbound(a,1)==1
而不是lbound(a,1)==0
,因为总的数组大小为零元素。谢谢!